Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Looping - API Call

Hi All,


I have an api call that only returns 50 results at a time, and I need to run it multiple times to build my result table.


Example:  myapi/getlist?limit=50&page=1   where page 1 is results 1-50, page 2 is results 51-100, etc.


How can make multiuple calls, updating page to page+1 each time, ultimately building one result table?  The reading I've done on looping hasn't gotten me very far.  Thanks!  Dave

Super User II
Super User II

Super User II
Super User II

@ImkeF  - got it working, thank you.  Ended up doing it by records, not pages, but basically the same result


Here's what I ended up with:


url = "myapi/getlist?&limit=50&offset=0",

Source = ((Web.Contents(url, [Headers=[#"Content-Type"="application/json"]]))),


#"Imported JSON" = Json.Document(Source,65001),

Custom1 = List.Generate( () =>
     [Result = #"Imported JSON", Offset = 0],
     each [Result][response][count] > ([Offset]),   //api returns a total record count as "count" in the response section
     each [
          Result = Json.Document(Web.Contents(url & "&offset=" & Text.From([Offset] + 50) )),
     Offset = [Offset] + 50


Hi @ImkeF


I've noticed you seem to be the go to person for looping API calls, was hoping you could go over my code and see where I'm going wrong. 


This is what I've currently have - 


ProjectID = "135353", // Type Dalux ProjectID
iterations = 20,
Bookmark1 = "0",
url = "" &
ProjectID &
"/Approvals?key=[API KEY]&bookmark=",

(url, Bookmark1) as record =>
Source = Json.Document(Web.Contents(url & Bookmark1)),
data = try Source[ApprovalsList] otherwise null,
next = try Source[NextBookmark] otherwise null,
res = [Data = data, Next = next]

GeneratedList =
() => [i=0, res = FnGetOnePage(url, Bookmark1)],
each [i] < iterations and [res][Data] <> null,
each [i=[i]+1, res = try FnGetOnePage(url & [res][Next]) otherwise null],
each [res]


The image below is the result of the query:




 The function is working and is able to call the first batch of results but then it fails to replace Bookmark1 for the Next cursor and terminates the list. 


Any suggestions?


Thank you in advanced. 


Best regards, 



That sure looks like what I'm after, thank you.  Might have some follow up questions as I get into it!

Super User IV
Super User IV

I know I have seen @ImkeF solve this before. 


@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!

Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Helpful resources



We are excited to announce the Power BI Super Users!

Microsoft Ignite

Microsoft Ignite with Arun Ulag

Featured Session: Drive Data Culture with Power BI- Vision, Strategy & Roadmap. Register here #MSIgnite #PowerPlatform #Power BI ​

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!


The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors