REST - POST - GET Wait Loop while report runs (IF THEN)

Hello RESTers :slight_smile:

Here is my current pickled situation.
20220817_114853_knime

While trying to convert my old python code to Knime friendly nodes ( yes i know I can use the python node, but that’s not the point here).
I am trying to recreate an if…then… structure arount the API answers.

1)POST call node for requesting the server to run a report
2) I parse the response to get the report ID
3) Manipulate the string to build new URL that includes the report ID
4) GET call to get the status of the report
5) Parse json to extract the running status of the report

and this is where i am stuck

IF “GET node” replies status = “running” THEN
wait for 30 seconds
retry get node(step 4)
IFELSE “GET node” replied status = “completed” THEN
Continue workflow
ELSE
Send email

i’ve been trying to do this with IF switch nodes, rule engines, and the wait node, but i’m officialy lost on how to go from variable to row, back to variable, how to trigger the get node again.

Any and all help would be much appreciated

Workflow Sample
SalsifyAPI_IF.knwf (76.1 KB)

Hi @gbardon

For this, I would put the GET call for the status in a loop, evaluate the result and with a ruleset determine if the loop should be exited. I’m working with an API at the moment with the same requirements.

This section:

  • Waits for 15 seconds.
  • Performs the GET request to get the upload status.
  • Does some generic processing to get the field in the proper format, specific to my usecase.
  • Convert the result value to a variable, evaluate it and set a boolean equivelant string.
  • Pass this to the end loop to either move to the next iteration or exit.

Notes:
I work with a Recursive Loop end here because it can exit based on true/false variable value, which is very useful in this case.

image

I use a Variable Expression node to determine this value. If it has failed or is done, set the variable to true which makes the loop exit. If not, set it to false which makes the loop keep running forever until the first condition is met.

In your case, you would be evaluating it for something like:

if (variable("random_name").equals("completed")) {
    true
} else {
    false
}

I use these variables etc. later on again to determine which type of email I want to send out.

image

If you would like to have more details/guidance let me know and I’ll draft something later after working hours :wink:

4 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.