Here is the Python function for doing this. # This function takes the API URL and query string. It returns all of the JSON data from the API request that has # been broken up into pages of data. def GetPages(url,query): data = [] done = False while done == False: try: ret = requests.request('GET', url, headers=g_header, params=query) except requests.exceptions.ConnectionError: print('A connection error has occurred while getting the page information.\n') return None # Append the new data to the existing. data += ErrorCheck(ret) # Get the page URLs from the HTTP header of the API call and split it into the URLs. pages = ret.headers['Link'].split(',') # See if there is a page for the 'next' page of data. page = next((i for i in pages if 'rel=next' in i), None) if page != None: # Isolate the token and then add it to the new query. token = page.split('startingAfter=')[1] token = token.split('&')[0] query['startingAfter'] = token else: done = True return data The call to this would be something like: clientlist = GetPages(url,querystring) Where url is the full URL to the endpoint and querystring would be the parameters you want, like {'timespan':'30','perPage':'1000'}
... View more