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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors