Forum Discussion
Loop through a paginated API getting the ID of the last record
My company is rebuilding our API's so they are paginated now. The problem is, one of our parameters should be the last ID of the record however, in order to get the loop working I should get the ID of the last record and use as the parameter of the next API query. The ID's arent sequential, so summing up a value to the ID's wont work. The thing is: I need a way to get the table last record ID, get back to power query with that ID and do that loop until the API return a empty table. The flow chart would be something like this:
First request without last ID record -----> Query returns a table with ID's -------> Get ID of the last record -------> Use this ID as a parameter for the next request
1 Reply
- ImkeF
Community Champion
Hi Gekko1 ,
you can use the List.Generate function for it. In this blogpost I have shown a simple implementation for it:
How not to miss the last page when paging with Power BI and Power Query (thebiccountant.com)