Forum Discussion
DelVosa
2 years agoFrequent Visitor
WEB API : end of month loop dynamic list parameter
Hi
I am trying to connect to a web api secured with a key and secret. The code below works perfect for 1 parameter (date in red below), which is the end of month in YYYYMMDD. I need this data for every end of month starting 30/09/2023 till most recent end of month available. So today, this would be 30/11/2023; per 01/01/2024 this should be 31/12/2023...
I want to create some sort of loop to fetch the data for multiple periods. How can I create some sort of dynamic list to do this?
Thanks a lot!
Jordy
let
authKey = "Basic " & Binary.ToText(Text.ToBinary(#"API Key" & ":" & #"API Secret"),0),
GetJson = Web.Contents(url,
[
Headers = [#"Authorization"=authKey,
#"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"],
Content = Text.ToBinary("grant_type=client_credentials")
]
),
FormatAsJson = Json.Document(GetJson),
AccessToken = FormatAsJson[access_token],
AccessTokenHeader = "bearer " & AccessToken,
GetJsonQuery = Web.Contents("https://asb-apps.wom.com/ords/wom/commitdataservice/wip?snapshotdate=20231130",
[
Headers = [#"Authorization"=AccessTokenHeader]
]
),
FormatAsJsonQuery = Json.Document(GetJsonQuery),
#"Converted to table" = Table.FromList(FormatAsJsonQuery, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
#"Converted to table"
1 Reply
- lbendlinSuper User
Instead get the first date of the current month (via #date(year,month,1) ) and subtract 1.
If you want this code to run on a schedule you need to change your URL to include a "Query" parameter.