Forum Discussion
API Pagination Cursor
Thank you amitchandak , but i've tried those topics and i wasn't able to adapt it to my code.
To solve an unfamiliar problem, try breaking it down into the smallest possible challenge. Right now you don't know how to handle pagination, so focus on solving that by getting everything else out of the way.
Create a copy of your query, remove everything but the source, turn that query into a function, and try adding pagination as explained in the links Amit gave you. Once you have pagination working, you can add back all the post-API processing from your initial query.
- gustavofiretti4 years agoFrequent Visitor
Hello otravers .
I tried to do this, i deleted all of the unecessary code and now i got this:
let Token = "XXX", iterations = 2, url = "https://api.deskbee.io/v1.1/bookings?", Source = Json.Document(Web.Contents(url, [Headers=[Authorization=Token]])), FnGetOnePage = (url) as record => let data = try Source[data] otherwise null, next = try Source[links][next] otherwise null, res = [Data=data, Next=next] in res, GeneratedList = List.Generate( ()=>[i=0, res = FnGetOnePage(url)], each [i]<iterations and [res][Data]<>null, each [i=[i]+1, res = FnGetOnePage([res][Next])], each [res][Data]) in GeneratedListBut now i got the same data from page 1 twice (number os iterations) i'm not getting the new page's data yet.
I'm not a dev, so I'm basicly trying to replace the code and adapting it to my case.
- otravers4 years agoCommunity Champion
You're making progress. "Being a dev" starts with thinking logically. How does your API handle paging? Is it a URL parameter? Or something in the header? You have to make the API aware of the page you want to retrieve each time you call it.
- gustavofiretti4 years agoFrequent Visitor
The API gives me another URL to the next page, like that:
But for some reason, the code is not replacing this new URL.
about the logic, i think i'm in the righ way, but i don't know much about M language.
I understand that the code need to generate a list, then replace de last url for the next url and generate a new list and then combinate those lists.
The other thing is i think that i don't need the iteration number, because i need to do this loop until the link "next" be null.