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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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.

amreet11
Frequent Visitor

Hi,

 

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

 

Thanks,

 

Amreet

BRVL
Frequent Visitor

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors