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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
paulorojog
Regular Visitor

Cursor Paginated data from Web API with List type outcome

Hi everyone!

 

I am calling a web api from an app provider (https://api.medilink.healthatom.com/api/v1/) to grab some data which is paginated and I am struggling with how to get the next page of data as it is cursor based. I've researched in previous post and videos and the difference it seems to be the type of records.

 

Here is all the documentation from the API. I think especially maybe the coursors have some relation to the problem and would help to have more context: https://api.medilink.healthatom.com/docs/#cursores

 

Through my investigation, by the moment I've created the following function "GetData" and brings effectivelly 50 records, which is the expected behavior because the data is paginated in that number:

 

GetData Function

 

(url as text) as record =>
let
    Source = Json.Document(Web.Contents(url, [Headers = [Authorization="Token tokencode"]]))
in
    Source

 

 

Result

paulorojog_0-1617606024124.png

 

Open data there are the 50 records, record has the link from the current and next page:

paulorojog_1-1617606075978.png

...

 

Then I've tried to add a pagination query based on other posts but I'm receiving the following error from the row 2 onwards; the first row has the first 50 records:

 

Query

 

let
myList = List.Generate( ()=>
    [Result = GetData("https://api.medilink.healthatom.com/api/v1/prestaciones"), Counter = 0],
    each  [Counter] < 5,
    each [Result =  GetData(Table.LastN([Result]{[Name = "link"]}[Table], 1){0}[#"Attribute:href"]), Counter = [Counter]+1],
    each [Result])
in
    myList

 

 

Result

paulorojog_5-1617608041057.png

paulorojog_6-1617608078500.png

 

Some related content I've already read is:

https://community.powerbi.com/t5/Desktop/Cursor-Paginated-data-from-Web-API/td-p/1029953/page/1

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

 

Thank you!

 

 

 

 

2 REPLIES 2
v-alq-msft
Community Support
Community Support

Hi, @paulorojog 

 

Are there any error messages in the query? You may try Record.Combine to bring records together.

 

Best Regards

Allan

 

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

paulorojog
Regular Visitor

Hi everyone, 

 

I'm still working on this. I've created a second function that I think is working, but still I need some help. The problem now is I have different GeneratedList{0}, {1}... but I can not see it all. How could I bring together all lists?

 

Function GetData2 ("links" is the record where the coursors of the API are located)

 

(url as text) as record =>
   let
    Source = Json.Document(Web.Contents(url, [Headers = [Authorization="Token tokencode"]])),
    data = try Source[data] otherwise null,
    next = try Source[links][next] otherwise null,
    res = [Data=data, Next=next]
   in
    res

 

 

 

 

Query (10 iteraciones)

 

let
 GeneratedList =
  List.Generate(
   ()=>[i=0, res = GetData2("https://api.medilink.healthatom.com/api/v1/prestaciones")],
   each [i]<10 and [res][Data]<>null,
   each [i=[i]+1, res = GetData2([res][Next])],
   each [res][Data])
in
    GeneratedList

 

 

Result

List with 1 row "Error" (no info about the error). But if I open that error row, I got 50 records from the GerenatedList{0}. Then if I change 0 per 1 or two, I got the other records but they are all separated.

 

paulorojog_0-1617688238354.png

paulorojog_2-1617688292930.png

 

Please any help would be appreciated! Thank you!

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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