Skip to content

Instantly share code, notes, and snippets.

@ryandhubbard
Created April 28, 2024 17:08
Show Gist options
  • Save ryandhubbard/57c9b433c55f2953eb1c5a298e14b718 to your computer and use it in GitHub Desktop.
Save ryandhubbard/57c9b433c55f2953eb1c5a298e14b718 to your computer and use it in GitHub Desktop.
def fetch_paginated_data(url, params,headers):
all_results = []
response = requests.get(url, headers=headers, params=params)
data = response.json()
# print(data)
all_results.extend(data['interactions'])
# print(all_results)
while 'next' in data['links']:
params = {} # Reset params for the next page
next_url = data['links']['next']
response_next = requests.get(next_url, headers=headers)
data_next = response_next.json()
# print(data_next)
all_results.extend(data_next['interactions'])
data = data_next # Update data to the next page's data for the next iteration
# print(all_results)
return all_results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment