Forum Discussion
Dynamic DataSource Error - RelativePath and Query?
- 2 years ago
Hi leemat
As an example of creating a Web data connection using URL and Relative Path, you can see an example in the below that I use to extract Strava data:
let RelativePath = "/" & AthleteID & "/stats", Payload = [RelativePath = RelativePath, Headers=[Authorization = "InsertTokenHere"]], Source = Web.Contents("https://www.strava.com/api/v3/athletes", Payload), JSON = Json.Document(Source) in JSON
_____________________________________________________
I hope my comment was helpful.
If your question was answered, please mark your post as 'Solved' and consider giving me a 'Thumbs Up'.
Find me on LinkedIn, Sessionize, or my blog Downhill Data
Hi leemat
As an example of creating a Web data connection using URL and Relative Path, you can see an example in the below that I use to extract Strava data:
let
RelativePath = "/" & AthleteID & "/stats",
Payload = [RelativePath = RelativePath, Headers=[Authorization = "InsertTokenHere"]],
Source = Web.Contents("https://www.strava.com/api/v3/athletes", Payload),
JSON = Json.Document(Source)
in
JSON
_____________________________________________________
I hope my comment was helpful.
If your question was answered, please mark your post as 'Solved' and consider giving me a 'Thumbs Up'.
Find me on LinkedIn, Sessionize, or my blog Downhill Data
This worked great for a single page of the data. Would it be alright to ask you another question?
It seems to be failing (returning nothing) when trying to extend to additional pages. Am I somehow breaking the code when doing the following?
GetPages = (url as text) =>
let
GetPageData = (url as text, optional nxtToken as text) =>
let
executionPath = executionId & "/results" & "?pageSize=1000" & nxtToken,
Payload = [RelativePath = executionPath, Headers=[Authorization="Bearer " & token, Accept="application/json"]],
SourceGet = Json.Document(Web.Contents(url , Payload)),
dataGet = try SourceGet[data] otherwise null,
nextTokenGet = try SourceGet[nextToken] otherwise null,
Encoded = try Uri.EscapeDataString(nextTokenGet) otherwise null
in
[Data = dataGet, NextToken = Encoded],
initialData = GetPageData(url),
accumulatedData = List.Generate(
() => initialData,
each [NextToken] <> null,
each GetPageData(url , "&nextToken=" & [NextToken]),
each [Data]
),
result = List.Combine(accumulatedData)
in
result,