I created a web contents object within a function to query an API endpoint in power query. I use a list generate to dynamically increase the records in that list, however, I can't seem to figure out how to increase the offset by 100.
At the moment I get the first 200 records and records 100 - 200 for every API call after that. I want the offset value to increase by 100, however. At the moment it is set to 100. So it should be first API call offset 0, next offset 100, next offset 200 and so on.
Does anyone have a glue?
let
getJournals = (page as number) =>
let
// Get Tenant ID from table
Source = Excel.CurrentWorkbook(),
#"Expanded Content" = Table.ExpandTableColumn(Source, "Content", {"TenantID",
"Client_Name", "ID"}, {"Content.TenantID", "Content.Client_Name", "Content.ID"}),
#"Content ID" = #"Expanded Content"{2}[Content.ID],
TenantID = #"Content ID",
// Query database for access token
tokenQuery = Sql.Database("XXX", "XXX", [Query="Select accessToken,
refreshToken from XXX WHERE systemName = 'XXX'"]),
accessTokenValue = tokenQuery{0}[accessToken],
// initialise request data
//authorization = "Bearer " & accessTokenValue,
accept = "application/json",
contentType = "application/json",
endPoint = "https://api.xero.com/api.xro/2.0/Journals?offset="& Number.ToText(page),
//Create web element
data = Json.Document
(
Web.Contents(
endPoint,
[
Headers =
[
#"Authorization" = authorization,
#"Accept" = accept,
#"Content-Type" = contentType,
#"xero-tenant-id" = TenantID
]
]
)
)
in
data,
increase = 100,
allJournals = List.Generate(() => getJournals(0),
each not List.IsEmpty([Journals]),
each getJournals(increase)),
#"Converted to Table" = Table.FromList(allJournals, Splitter.SplitByNothing(), null, null,
ExtraValues.Error)
in
#"Converted to Table"