Merge REST array getting logic into one function.