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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
BRVL
Frequent Visitor

Web based cursor pagination issue

Hi I’ve been working on trying to use List.generate to create a paginated list from the api. My issue is that my api uses Cursor-Based Pagination. A single request will give me two sections if a cursor exists i.e next page

BRVL_10-1663772464272.png

 or one section if it's the final page

BRVL_5-1663769504207.png

If "cursor" is exists, I need to make another request, using the "cursor" value given to get the next page of company records, "payments" is the actual information I need.

BRVL_9-1663772095850.png

The issue is that in the last record the field "cursor" does not exist.

BRVL_7-1663770099679.png

BRVL_8-1663770107792.png

I can't seem to figure out how to write the query to get all the records but to stop list.generate when the field cursor does not exist.

 

when i try  - each Record.HasFields( _ , "payments" ) = true  , this returns all the pages/rows but causes the error above as the final page has no cursor field.

 

when i try - each Record.HasFields( _ , "cursor" ) = true  , this returns only the first two pages but not the final page.

 

I've tried - try each Json.Document(Web.Contents("https://connect.squareup.com/v2/payments?cursor=" & ( try Text.From([cursor]) otherwise null) , [Headers=[Authorization=" token "]] )) otherwise null ) and other variations but can't seem to get it to what i want.

 

Any help would be great.

2 ACCEPTED SOLUTIONS
v-yanjiang-msft
Community Support
Community Support

Hi @BRVL ,

Have you tried to use if function like this:

each if Record.HasFields(_,"cursor")=true then Json.Document(... else...

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Nevermind, I've figured it myself.

View solution in original post

6 REPLIES 6
v-yanjiang-msft
Community Support
Community Support

Hi @BRVL ,

Have you tried to use if function like this:

each if Record.HasFields(_,"cursor")=true then Json.Document(... else...

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Nevermind, I've figured it myself.

Anonymous
Not applicable

Hi,

 

Would you mind sharing how you resolved the issue as I am struggling with a similar problem.

 

Thanks,

 

Amreet

I used the below and it solved it for me: 

 

data = let
Pagination = List.Generate( ()=> Source,
each [payments] <> null ,
each if Record.HasFields(_,"cursor") and [cursor] <>null then Json.Document(Web.Contents("https://connect.squareup.com/v2/payments?cursor=" & Text.From([cursor]), [Headers=[Authorization="Token"]] )) else Record.FromList({null, null}, {"payments","cursor"} ))


in Pagination,
#"Converted to Table1" = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Ignore)

jrush4
Frequent Visitor

Any chance you could give a little more context on how you got this working? I'm currently trying to do something similar with pagination, but can't crack it. Your above code has gotten me closer, but I'm still not there!

Hi thanks for your reply but this does not change the result.

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.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

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.