Skip to main content
6 of 6
Code correction

Combine multipage API results in Mathematica

Updated to show more code

Can't seem to find a good post/answer to this so I'm asking the question.

I'm pulling data from the Swarm/Foursquare API, and it's paged (max 250 results per pull):

url = StringTemplate[ "https://api.foursquare.com/v2/users/self/checkins?startTime=`a`&\ endTime=`b`&oauth_token=`c`&limit=250&offset=`d`&v=20220406"][<| "a" -> startTime, "b" -> endTime, "c" -> oauthToken, "d" -> offset|>]; response = Import[url, "RawJSON"]; checkins = response[["response"]][["checkins"]][["items"]]; Until[Length[response[["response"]][["checkins"]][["items"]]] == 0, offset += 250; url = StringTemplate[ "https://api.foursquare.com/v2/users/self/checkins?startTime=`a`&\ endTime=`b`&oauth_token=`c`&limit=250&offset=`d`&v=20220406"][<| "a" -> startTime, "b" -> endTime, "c" -> oauthToken, "d" -> offset|>]; response = Import[url, "RawJSON"]; AppendTo[checkins, response[["response"]][["checkins"]][["items"]]] ] 

I should have around 1,200 results. Instead, I have 256. What am I doing wrong here?