Forum Discussion
API Pagination Cursor
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
GeneratedList
But 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.
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.
- BRVL3 years agoFrequent Visitor
see my post: Solved: Re: Web based cursor pagination issue - Microsoft Power BI Community
should help since it's cursor based pagination.