Forum Discussion
Anonymous
2 years agoNot applicable
Converting Base64 value to use in pagination
Hello all, I have a working solution that I am looking to improve, The challenge I am running into is this, the api I am connecting to uses page [size] with a max of 100 and page[number] which return...
Anonymous
1 year agoNot applicable
Still trying to figure this out, the below code only returns page one. The "url" parameter is the full url for page one and "Token" is the key
et
// Base URL
baseUrl = "https://apis-us.MYAPI.com",
initialUrl = baseUrl & "/v1/dep/13473/projects?page[size]=100&page[number]=MQ==",
// Function to get data from a given URL with authorization header
GetPage = (url as text) as record =>
let
response = Json.Document(Web.Contents(url,
[Headers=[Authorization=Token, #"Content-Type"="application/vnd.api+json"]]
)),
data = if Record.HasFields(response,"data") then response[data] else {},
links = if Record.HasFields(response, "links") then response[links] else null,
nextLink = if links <> null and Record.HasFields(links, "next") then links[next] else null,
nextUrl = if nextLink <> null and Text.StartsWith(nextLink, "http") then nextLink else baseUrl & nextLink
in
[Data = data, NextLink = nextUrl],
// Function to loop through pages and combine data
GetAllPages = (url as text) as table =>
let
firstPage = GetPage(url),
allData = List.Generate(
() => firstPage,
each _[NextLink] <> null,
each GetPage(_[NextLink]),
each _[Data]
)
in
Table.Combine(List.Transform(allData, each Table.FromList(_, Splitter.SplitByNothing()))),
// Initial call to get all pages
result = GetAllPages(initialUrl)
in
result