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

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.

Reply
Asynchronism
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

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

5 REPLIES 5
ImkeF
Community Champion
Community Champion

@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 - 

 

let
ProjectID = "135353", // Type Dalux ProjectID
iterations = 20,
Bookmark1 = "0",
url = "https://field.dalux.com/service/APIv2/FieldRestService.svc/v2.2/Projects/" &
ProjectID &
"/Approvals?key=[API KEY]&bookmark=",


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


GeneratedList =
List.Generate(
() => [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]
)
in
GeneratedList

 

The image below is the result of the query:

 

Ricardo_MSS_0-1603958833042.png

 

 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, 

 

Ricardo. 

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

Greg_Deckler
Community Champion
Community Champion

I know I have seen @ImkeF solve this before. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Kudoed Authors