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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sellersmd
Frequent Visitor

REST API pagination with a "nextToken" - how to iterate through pages

Hello,

 

I am an beginner/intermediate-level Power User, and am new to accessing APIs through Power Query. I am feeling pretty confident today - I have successfully fetched the bearer token for my API and made several successful API calls for various data. I am stuck on the next part of the puzzle.

 

The API I am accessing limits results to 100 per page, so I will need to fetch multiple pages of results and then merge them together into a single query. The tricky part is that *if* there is a next page, the API returns a token called "nextToken" to indicate that there is a next page, and that token must be fed back to the API in order to fetch the next page. Hence, there is no way of knowing how many pages of results, you just have to wait until a response without a "nextToken" is received.

 

I would like to build something akin to a While() loop in other programming languages that works as follows:

 

nextTokenExists = FALSE

 

(fetch first page of results - got this done already)

check for nextToken

 

While (nextToken = TRUE):

    fetch next page of results using nextToken value

    merge these results to first page of results

    check for nextToken again and update value

 

Ultimately this loop should end when the "nextToken" is not found in the API response, and I would like to end up with a single query that is a merger of all of the results from within the loop.

 

I don't have a clue where to get started on this in Power Query, and I don't think the sample data is really relevant, but the API documentation in question for the data I am fetching can be found here: https://spytec.readme.io/reference/get-alerts 

 

Please let me know if more information is needed. Thanks in advance!

 

 

4 REPLIES 4
Anonymous
Not applicable

Hi, @sellersmd Did you find a solution to this issue? I'm also researching it.

RicardoAGdSilva
Frequent Visitor

Anyone got an idea on this issue? I got the same problem

ppm1
Solution Sage
Solution Sage

This article has an example you can likely adapt (the datalist step of the 2nd approach).

Updated – Get SharePoint List Data … Fast – Hoosier BI

 

Pat

Microsoft Employee
RanjeetK
Helper I
Helper I

I have also same issue , i can get 100 records only and for next 100 i need to use NextToken from first result please help us

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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