Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Using Chris Webbs now infamous blog post, I have been able to create an API loop that successfully pulls a loop of an API (Zendesk chat data) which has a 'next_page' field attributed to it.
The below is the code which works fine on desktop but doesn't work in the service. I have been able to do this whilst incorporating the [startepochtime] which is a seperate basic query giving me the correct start time of my call 3 months ago.
I have tried what feels like a thousand times to use relative path, query etc etc. but when do so it just incessently loops the same page over and over.
PLEASE help!
let
iterations = 10000, // Max Number of iterations
url = "https://www.zopim.com/api/v2/" & "incremental/" & "chats?fields=chats(*)" & "&start_time=" & Number.ToText( StartEpochTime ),
FnGetOnePage =
(url) as record =>
let
Source1 = Json.Document(Web.Contents(url, [Headers=[Authorization="Bearer MY TOKEN GOES HERE"]])),
data = try Source1[chats] otherwise null, //get the data of the first page
next = try Source1[next_page] otherwise null, // the script ask if there is another page*//*
res = [Data=data, Next=next]
in
res,
GeneratedList =
List.Generate(
()=>[i=0, res = FnGetOnePage(url)],
each [i]<iterations and [res][Data]<>null,
each [i=[i]+1, res = FnGetOnePage([res][Next])],
each [res][Data])
Can you clarify what doesn't work about your original query (the one that works in PBIDesktop but not in the service)? And when you're trying to modify it, are you seeing the "repeatedly pulling the same page" behavior in PBIDesktop or only in the service?
Hi @stubaby ,
I found some similar posts which might help you:
Solved: PowerBI API call with loop - Microsoft Power BI Community
Solved: Looping through Parameters for API calling - Microsoft Power BI Community
How to use List.Generate to make API Calls in Power Query M - Gorilla BI
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 18 | |
| 9 | |
| 9 | |
| 6 | |
| 6 |