Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi,
I am using query editor to make an API call to one of our internal API services. The script I have developed consists of 3 api calls, the 1st is to obtain a token id which is straightforward, 2nd api call is a post request to pass it some parameters by end users. A task id is retrievable from this 2nd call. This task id is used then as part of the 3rd and final api call (get request) to return the results. The problem I have is the 2nd api call execution time can vary so if I call the 3rd api call too early, the results will not be returned. The task status can be one of 3 statuses - null, in-progress and finished. I can only get the results once the status is in "finished" state.
The variable "url_main" (seen below) is dyamanic and contains the task id generated from the 2nd api call. I need some type of loop on the 3rd api call (get request) to keep calling the api and only return the results once the task status changes to finished.
Here is a sample snippet of the 3rd api call where I am trying to apply a list generate and web.contents together. The below keeps returning an emtly list where I want to keep looping until the task status turns to finished.
let
url_main = "https://xxxxxxxx"
mytok = "xxxxxxxx"
// funciton to make api call
fetchData = () => // No argumens to pass into function
let
source = Json.Document(Web.Contents(url_main, [Headers = [//IsRetry = "true",
clearCahceTry = Text.From(Number.Random()),
#"Authorization"= "Bearer " & mytok]]))
in
source,
// loop
let
mysource = List.Generate(() =>
[counter = 1, Result = fetchData()],
//each [Result][taskStatus] = Text.ToList("FINISHED"), // condition if true
each [Result][taskStatus] = "FINISHED", // condition if true
//each not List.IsEmpty( [Result] ), // condition if true
each [
counter = [counter] + 1,
Result = try fetchData() otherwise null],
each [Result] // selects part of the result to return if condition is met
)
in
mysource
Any help would be great.
Thanks in advance
Alan
What should happen if it never finishes?
Read about Function.InvokeAfter()