Repeat API request if defined condition is not met

Hi all,
in our workflow we are requesting a 3rd party API. We submit some data and wait for it to finish.

The 3rd party api has and endpoint to check the status and responds with

"{...., "finished:"false", ... }

the next component in our workflow must not run until the response is "finished":"true"

I red through the loop documentation but it was not clear to me where i can define the condition.

Hey @whynot - I don't think you want to use the "Loop" block for this particular use case. In fact, I don't think there's a built-in component that would really suit your need. You can definitely implement this with a JS code block, though!

A really rough implementation might look something like this:

In this example, we're making the initial call to the API in the left block and then looping inside the right block until our status check returns {..., finished: 'true'}. Note that we're using the axios library to make our request to the status check API from within our JS code. You can read about enabling additional libraries here and about axios, in particular, here.

The use of the await keyword forces this code to evaluate in a synchronous manner, meaning the workflow won't proceed until we reach our end condition. If you anticipate that it will take more than 10 seconds for this to happen, you'll need to up the timeout on the JS code block via the block settings.

I hope that helps! Definitely follow up here if you have any additional questions about implementing this.

Hi Darren, thanks for this input.
I tried to implement it and failed due to "axios is not defined (line 1)" error

I added the library already (v1.7.6):
image

I cleared cache, restarted browser, logged in/out, but still does not work:
image

I then tried with the node-fetch package, here the package gets recognized but same error anyway:
image

Any other idea?

Ah I think I neglected to mention that you'll need to add const axios = require('axios') in the "Settings -> JavaScript configuration" menu!

1 Like

Actually we did that, still it did not work. The solution can be found here: