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
Anonymous
Not applicable

Issue fetching paginated data from a REST API

Dear all,

i'm currently confronted with a pagination issue when getting data from a REST Apo.

 

When querying the REST API with a custom query i get the total of pages in return, but the query is repeating the data from the first page, and it doesn't return fetch the data from the others pages.

 

The custom query im using

 

let
BaseUrl = "--",
Token = "--",
EntitiesPerPage = 50,

GetJson = (Url) =>
let
Options = [Headers=[access_token="--", Accept="--", #"Content-Type"="--"]],
RawData = Web.Contents(BaseUrl, Options),
Json = Json.Document(RawData)
in Json,

GetEntityCount = () =>
let Url = BaseUrl & "$count=true&$top=0",
Json = GetJson(Url),
Count = Json[#"count"]
in Count,
GetPage = (Index) =>
let Skip = "$offset=" & Text.From(Index * EntitiesPerPage),
Url = BaseUrl & Skip,
Json = GetJson(Url),
Value = Json[#"items"]
in Value,

EntityCount = List.Max({ EntitiesPerPage, GetEntityCount() }),
PageCount = Number.RoundUp(EntityCount / EntitiesPerPage),
PageIndices = { 0 .. PageCount - 1 },
Pages = List.Transform(PageIndices, each GetPage(_)),
#"Converted to Table" = Table.FromList(Pages, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandListColumn(#"Converted to Table", "Column1"),
#"Expanded Column2" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1", {"href", "id", "firstName", "lastName"}, {"Column1.href", "Column1.id", "Column1.firstName"})
in
#"Expanded Column2"

 

I'm a newbie in Power Query so kindly ask your support & suggestions on how to resolve this issue.

 

 

1 REPLY 1
Greg_Deckler
Super User
Super User

@ImkeF @edhans 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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