Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Cursor Paginated data from Web API

Hi,

 

I am calling a web api 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.

 

When I call the api in PowerQuery (I'm connecting through a Web datasource) the Navigator returns a table with two rows, the first row that contains a table of data that I'm requesting and a second row that contains a table that contains the original url but with a cursor parameter appended to it. 

so the structure looks like this:

 

Original api call = https://api.myapiurl.com/v1/channel/1234/webcasts

 

which produces:

 

NameTable
webcastTable
linkTable

 

The link table contain the following:

 

hrefrel
https://api.myapiurl.com/v1/channel/1234/webcasts?cursor=6789next

 

I can expand the webcast row which contains the data without any problems but how do I then call the next page of data and store it with the first call and then continue until I have all the available data?

 

Many thanks!

23 Replies

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi ImkeF 

         

        Many thanks for the help and resources.  I've read through it and I feel like I'm almost there but I just can't quite join the dots. I'm very new to PowerQuery so some of the syntax is still a bit of a mystery to me but I'm getting there!

         

        My data is returned as xml (I don't think that will make much difference) and the last  row of the page has two fields, Attribute:href and Attribute:rel.  The rel field contains the word next and the rel field a complete url with the cursor for the next page. The API documentation states that when the last page is reached there will be no value in the rel field.

         

        As I understand it, I can use the List.Generate function and effectively 'loop' through the data and pass the next url and grab the next page of data.  I can't seem to figure out how to reference the fields from my Source and use it to get the next set of data.  This is what I have so far (which doesn't work!)

         

        let
            Source = Xml.Tables(Web.Contents("https://api.myWebService.com/v1/channel/1234/webcasts")),
            #"Expanded Table" = Table.ExpandTableColumn(Source, "Table", {"title", "description", "presenter", "duration", "start", "keywords", "published", "visibility", "url", "status", "active", "created", "lastUpdated", "link", "Attribute:id", "syndicationType", "Attribute:href", "Attribute:rel"}, {"Table.title", "Table.description", "Table.presenter", "Table.duration", "Table.start", "Table.keywords", "Table.published", "Table.visibility", "Table.url", "Table.status", "Table.active", "Table.created", "Table.lastUpdated", "Table.link", "Table.Attribute:id", "Table.syndicationType", "Table.Attribute:href", "Table.Attribute:rel"}),
            myTest = List.Generate( ()=>
                [Result = Source, Counter = 0],
                each [Result][[Attribute:href] <> null and [Counter]< 20,
                each [Result = Xml.Tables(Web.Contents([Attribute:href])),
                Counter = [Counter] + 1]
        
            )
        in
            myTest

         

        Any pointers you could provide in getting this right would be greatly appreciated! 

  • ChaitanyaSai's avatar
    ChaitanyaSai
    Regular Visitor

    Hi Team,
    I have an issue while fetching the Data from Cursor Based Web API, Could Some help Me with the M-Script with header value. I have tried with Some Which is causing me a Pop of Authentication with the Manual Refresh as Below and I am unable to see the Data Sources after publishing it into the POwerBI Services.

    Appreciated if supported.
    thank you .