Forum Discussion
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:
| results | continuationToken | EarliestEntryDate |
| List | nvjkfjhg9476rhfkf0y78 | 6/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:
What am I doing wrong here?
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 MCode 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] )
5 Replies
- AlexisOlsonSuper 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 MCode 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] ) - V-yubandi-msftCommunity 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.
- V-yubandi-msftCommunity 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.- v-achippaCommunity Support
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-msftCommunity 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.