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
Lethabo5
Frequent Visitor

Retrieving data from a paginated API

Hi 

 

I am trying to retrieve data from this API. It is paginated. But I keep getting this error

  1. Expression.Error: We cannot convert a value of type Table to type List. Details: Value=Table Type=Type

    I am not sure what I'm doing wrong.  I am very new to M. Any assistance will be greatly appreciated
     

    let

      ufnGetList = (pgToken) =>

       let

       actualUrl = "https://api.XXXXXXXXX.com/v1/user",

       options = [Headers =[#"Content-type"="application/json",

                  #"Authorization"="Bearer eyXXXXXXXXXXXXXXXXXXXXXX"]],

        result = Web.Contents(actualUrl, options),

     

      nextPageToken = try result[nextPageToken] otherwise null,

      items = result[items],

      record = [items = items, nextPageToken = nextPageToken]

      in

      record,

     

      resultSet = List.Generate(

              () => ufnGetList (""),

              each _[nextPageToken] <> null,

              each ufnGetList(_[nextPageToken]),

              each [nextPageToken =_[nextPageToken], items =_[items]]

      ),

      lastPageToken = List.Last(Table.FromRecords(resultSet)[nextPageToken]),

      lastResultSet = ufnGetList(lastPageToken)[items],

     

      fullResultSet = Table.Combine({Table.FromRecords(List.Combine(Table.FromRecords(resultSet))), Table.FromRecords(lastResultSet)})

      in

      fullResultSet

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Lethabo5 ,

 

Remove Table.FromRecords in List.Last.

 

List.Last(resultSet)[nextPageToken],

 

 

Community Support Team _ Sam Zha
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

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@Lethabo5 ,

 

Remove Table.FromRecords in List.Last.

 

List.Last(resultSet)[nextPageToken],

 

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.