cancel
Showing results for 
Search instead for 
Did you mean: 
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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Top Solution Authors
Top Kudoed Authors