Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Rest API - call the next page URL without knowing total rows or total pages

Hi Everyone, 

 

This is my first time working with a REST API in Power BI and I'm running into an issue with pagination...

 

I have an initial GET that calls out to a REST service which returns 100 results and a link for the next 100 results. This link is the same GET call but with an additional parameter page_token. So I need PowerBI to basically capture the results and then continue to loop through the rest of the results using this parameter and combine all the results together. 

 

I know there is quite a bit of documentation on pagination, like this Community post and this article by the BI Accountant, but all the solutions I can find require either knowing the total records or total pages or have the next page url listed explicitely in the inital record.

 

In my case, when the API is called, it returns this initial record. 

 

margaret_1-1652464735216.png

But you have to click into Pagination in order to grab the next URL:

margaret_2-1652464991514.png

 

Based on my research, I was able to piece together this List.Generate function, but I'm having trouble understanding how this would all come together -- how do I tie the next record from above into this List.Generate? 

 

margaret_3-1652465778911.png

 

Thanks in advance for your thoughts!

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

The next page url is stored in Result[_pagination][next] so try this

 

 

let
    Source = List.Generate( () =>

        [ URL = "https://api2.frontapp.com/" , Result = Json.Document(Web.Contents(URL)) ],

        each [URL] <> null,

        each [ URL = [Result][_pagination][next] , Result = Json.Document(Web.Contents([URL])) ]

    )
in
    Source

 

 

This code will end assuming that [_pagination][next] is null when there are no more records to retrieve.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

2 REPLIES 2
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

The next page url is stored in Result[_pagination][next] so try this

 

 

let
    Source = List.Generate( () =>

        [ URL = "https://api2.frontapp.com/" , Result = Json.Document(Web.Contents(URL)) ],

        each [URL] <> null,

        each [ URL = [Result][_pagination][next] , Result = Json.Document(Web.Contents([URL])) ]

    )
in
    Source

 

 

This code will end assuming that [_pagination][next] is null when there are no more records to retrieve.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Thank you Philip! That [_pagination][next] was the piece I was missing!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.