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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

5 REPLIES 5
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)

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors