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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
stubaby
New Member

Web API Loop Help

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])

 

 

2 REPLIES 2
Ehren
Microsoft Employee
Microsoft Employee

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?

Anonymous
Not applicable

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.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors