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
amreet11
Frequent Visitor

Issues with Cursor Pagination

Hi,

 

I am struggling to correctly pull information from a restaurant reservations API which uses cursor pagination. Calling the API directly produces the below result

amreet11_0-1674662595451.png

 

Accessing the "data" record provides the cursor to access the next page of data as well as the booking records themselves

 

amreet11_1-1674662650115.png

 

The API paginates until cursor = null

 

I have attempted to use List.Generate to access all of the pages of data, using the below posts as reference, but I have been unsuccessful in my attempts to adadpt them to my API requirements:

 

https://community.powerbi.com/t5/Power-Query/Need-Help-with-Stripe-REST-API-Pagination-in-Power-Quer...

https://datachant.com/2016/06/27/cursor-based-pagination-power-query/

https://community.powerbi.com/t5/Power-Query/Web-based-cursor-pagination-issue/m-p/2786453#M86457

 

I have attempted to modify the code to work for my scenario. However, when using the below code, it appears to continually loop, creating a huge dataset. For reference, I know that the call I am making has c. 1000 records, which means with a limit of 400 imposed by the API, there should be three pages of data.

let

     // Get the API Token

    api_url = "https://api.sevenrooms.com/2_4/reservations/export?venue_id" &venue_id&"&limit=400&from_date="&from_date&"&to_date="&to_date,

    from_date = "2023-01-01",

    to_date = "2023-01-31",

    venue_id = "XXXXXXXXXX",

 

   

    

    APICall =

 

        List.Generate

        (

                () => [APIData = Json.Document(Web.Contents (api_url,

                [

       

        

        Headers = [#"Content-Type"="application/x-www-form-urlencoded", #"Authorization"=Token ]

 

 

    ]

    ))[data] , MoreData = APIData[cursor], results = APIData[results]],

 

    each [results] <> null,

 

    each [ APIData = Json.Document(Web.Contents(api_url&"&cursor="&(try Text.From([MoreData]) otherwise null),

   

     [

       

        

        Headers = [#"Content-Type"="application/x-www-form-urlencoded", #"Authorization"=Token ]

 

 

    ]

    ))[data], MoreData = [APIData][cursor], results = [APIData][results]],

 

    each [APIData] ),

    #"Converted to Table" = Table.FromList(APICall, Splitter.SplitByNothing(), null, null, ExtraValues.Error),

    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"cursor", "limit", "results"}, {"cursor", "limit", "results"}),

    #"Expanded results" = Table.ExpandListColumn(#"Expanded Column1", "results")

in

    #"Expanded results"


This leaves me with thousands of rows of data (I assume because it is continually looping) rather than three cursors worth that should be generated:

 

amreet11_2-1674669270999.png

 

Could someone please help me out with refining the request to avoid this looping?


I am new to M langauge so any help would be hugely appreciated.

 

Thanks

0 REPLIES 0

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