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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
rdorsey
Frequent Visitor

Using List.Generate for Token-Based API Call

This is my first time building something like this and I'm missing something really fundamental. I built a function in M called "Output" which takes text as a parameter and runs an API call using that text as the continuation token. The API call gets the results from the system in descending order starting with the most recent entry. This function works great on its own and returns this:

 

resultscontinuationTokenEarliestEntryDate
Listnvjkfjhg9476rhfkf0y786/25/2025

 

The "EarliestEntryDate" field is the earliest date from the entries returned by the call. What I would like to do is repeatedly execute the "Output" function using the continuation token from the previous call until the "EarliestEntryDate" is less than a date of my choosing. To do this I tried following this guide and put together the following:

 

token_based_call =
List.Generate(
() => Output(""),
each List.Min(_[EarliestEntryDate]) > Date.FromText("6/15/2025"),
each Output(_[continuationToken]),
each _[continuationToken]
)

 

When I run this though I get this:

 
rdorsey_1-1750868311227.png

 

What am I doing wrong here?

5 REPLIES 5
V-yubandi-msft
Community Support
Community Support

Hi @rdorsey ,

Could you please let us know if your issue has been resolved, or if you're still experiencing any problems? Feel free to share if you need any additional details we're happy to assist further.

Regards,

CST Team.

V-yubandi-msft
Community Support
Community Support

Hi @rdorsey ,

Could you let us know if your issue has been resolved or if you are still experiencing difficulties? Your feedback is valuable to the community and can help others facing similar problems.


Thank You.

Hi @rdorsey,

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the issue is resolved? or let us know if you need any further assistance.
If any response helped in resolving the issue, please mark it as "Accept as solution" and give kudos if you found it helpful.

 

Thanks and regards,

Anjan Kumar Chippa

V-yubandi-msft
Community Support
Community Support

Hi @rdorsey ,

Thank you for reaching out to the Microsoft Fabric Community.  @AlexisOlson , has provided an good solution that follows recommended practices for using List.Generate, particularly for managing token based API pagination.

We encourage you to try this approach with your data and share your experience. Should you have any further questions or encounter any issues, please feel free to reach out.

 

Special thanks to @AlexisOlson,  for the quick and detailed response.


Best regards,

Fabric Community Team.

AlexisOlson
Super User
Super User

Your syntax doesn't look right to me.

 

Compare to the examples in this highly-related article:
How to use List.Generate to make API Calls in Power Query M

Code snippet from the article:

List.Generate( 
  ()  =>  [ Offset = 100, Pokemon = GetPokemon(0) ], 
  each [Offset] <= 200,  
  each [ Pokemon = GetPokemon( [Offset] ), Offset = [Offset] + 100 ],  
  each [Pokemon] 
)

 

Your code should probably look more like this:

List.Generate( 
  ()  =>  [ token = "", results = Output("") ], 
  each [results][EarliestEntryDate] > Date.FromText("6/15/2025"),
  each [ token = [results][continuationToken], results = Output(token) ],  
  each [results]
)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.