Forum Discussion
Get data - Json.document
- 6 months ago
Hi Olufemi7 & v-sshirivolu
Thank you very much for your quick response to my request.
Yesterday we finaly succeded in getting the query correct and the I now get the expected data in my datamodel - thank you very much for your input and support.
Hello HCJ2026,
This is expected behaviour the AutoPilot API is paginated.
Your query explicitly requests only page 1, so Power Query will return just that page. Power Query does not automatically fetch all pages; you must loop through them in M.
You need to implement pagination, for example with List.Generate:
let
BaseUrl = "https://api.autopilot.dk/v2/Timeregistrations",
GetPage = (Page as number) =>
Json.Document(
Web.Contents(
BaseUrl,
[
Headers = [
#"accept" = "application/json",
#"Content-Type" = "application/json",
#"APPartnerKey" = "YOUR_KEY",
#"APCompanyKey" = "YOUR_KEY"
],
Content = Text.ToBinary(
"{""page"":" & Number.ToText(Page) & ",""pageSize"":29999}"
)
]
)
),
Pages =
List.Generate(
() => [Page = 1, Data = GetPage(1)],
each List.Count([Data]) > 0,
each [Page = [Page] + 1, Data = GetPage([Page])],
each [Data]
),
Combined = List.Combine(Pages),
Result = Table.FromRecords(Combined)
in
Result
Microsoft docs confirm that REST APIs must be paged manually in Power Query and all pages must be explicitly combined: Paging
Thank you very much for your response.
I still get this error when I try to set it up: