Forum Discussion
Anonymous
4 years agoNot applicable
Dynamic API Pagination with next page Cursor in a Record
Hello, I am having issues with writing a custom Query to get some data from an API. In the initial response, I get these 2 results: data - (that has the 1st page of the data needed) a...
Anonymous
4 years agoNot applicable
Here is a copy of the Pagination code from the API documentation:
import requests
url = "https://api.samsara.com/fleet/vehicles"
params = {}
headers = {
"Authorization": "Bearer TOKEN"
}
hasNextPage = True
while hasNextPage:
response = requests.request("GET", url, headers=headers, params=params).json()
for vehicle in response["data"]:
# process each vehicle
hasNextPage = response["pagination"]["hasNextPage"]
params["after"] = response["pagination"]["endCursor"]
I'm having a hard time translating this into M script. Can someone help me out with the M code that would work?
- v-easonf-msft4 years ago
Community Support
Hi, Anonymous
You need to implement a for-loop using List.Generate.
About how to implement Cursor-Based Pagination using List.Generate to extract large data sets from Web APIs, please refer to below thread.
Iterate Over Dynamic Web API Pages With Power Query – How To Resolve Cursor-Based Pagination
Best Regards,
Community Support Team _ Eason