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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
bajesh007
Frequent Visitor

List.Generate function condition not met - REST API - Paginated results

Hello all,

 

Need your help with List.Generate function. I need to call paginated REST api end point recursively to fetch data until no more data exists as total number of pages is unknown. (Note : Only one parameter is supplied which is a standard scrollid generated by another rest end point).

 

Based on other posts, I tried calling a function and checking if [Result] is null, but doesnt seems to work as it is fetching more records than the original record count. (list is getting duplicated again and again!)

 

How to check if the List named "Exceptions" (shown below) has any data so that i can exit the custom function.

Url details:
http://server:9950/ExcpnReport?scrollid=AbcdefghIjkl

Sample Json output from above endpoint:
{"ScrollId": "AbcdefghIjkl", "Exceptions":[{TradeId:"XYZ","expected":10,"unexpected":15......}]}

 

Thanks in advance.

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @bajesh007 

 

You seem to have posted 2 separate questions about the same thing.  That's confusing!  Best to stick with just 1 post on each topic.  Close the other one.

 

There's a couple of things here that make this difficult.  You haven't said under what condition to terminate the API calls.  What value returned by the API tells you that there's no more data?

 

Secondly, the JSON data you've provided isn't complete so I can't write a query to parse that.  Need an entire response from the API to understand what data it returns, initially, while there ar emore records to retrieve, and when it's returned the last records.

 

I'd probably tackle this using something like this with List.Generate, but can't offer more without the information I just requested.

let
    Source = List.Generate(
    () => [ data = Json.Document(Web.Contents("http://server:9950/ExcpnReport?context=ab-20210511-40433&book=abcd&pagesize=25")), 
            ScrollID = ""
          ],

    each [ScrollID] < "???" ,  // What is the condition to terminate the loop ?

    each [ ScrollID = [data][ScrollID], data = Json.Document(Web.Contents("http://server:9950/ExcpnReport?context=ab-20210511-40433&scrollid="&[ScrollID])) ],

    each [data]
)
in
    Source

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

1 REPLY 1
PhilipTreacy
Super User
Super User

Hi @bajesh007 

 

You seem to have posted 2 separate questions about the same thing.  That's confusing!  Best to stick with just 1 post on each topic.  Close the other one.

 

There's a couple of things here that make this difficult.  You haven't said under what condition to terminate the API calls.  What value returned by the API tells you that there's no more data?

 

Secondly, the JSON data you've provided isn't complete so I can't write a query to parse that.  Need an entire response from the API to understand what data it returns, initially, while there ar emore records to retrieve, and when it's returned the last records.

 

I'd probably tackle this using something like this with List.Generate, but can't offer more without the information I just requested.

let
    Source = List.Generate(
    () => [ data = Json.Document(Web.Contents("http://server:9950/ExcpnReport?context=ab-20210511-40433&book=abcd&pagesize=25")), 
            ScrollID = ""
          ],

    each [ScrollID] < "???" ,  // What is the condition to terminate the loop ?

    each [ ScrollID = [data][ScrollID], data = Json.Document(Web.Contents("http://server:9950/ExcpnReport?context=ab-20210511-40433&scrollid="&[ScrollID])) ],

    each [data]
)
in
    Source

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors