Retry API call?

I have an API endpoint to a 3rd party that starts a process on their end. Then I have a 2nd endpoint that calls the status of that original request. I'd like to call that 2nd endpoint, and if the [state] property == 'In progress', then wait a bit, and re-run it. Eventually it will return 'Complete', or 'Approved' or something, and then I can move on down my branch.

I'm using a branch and some code to implement the wait, but I can't connect the wait block back to the previous query because it "creates a cycle". This is actually what I intend, but apparently it's forbidden. What's the best process to do this?

Thanks!

Here's a scrubbed screenshot if it helps for context.

Hey @pyee!

Thanks for asking this question during Office Hours on Tuesday. Just posting here as a follow-up for anyone else who might run into this:

At the moment, I would try using a Function Block inside of a code block to try the query until it succeeds. You could do something like

const maxTries = 10;
for(let i = 0; i < maxTries; i++){   
  const result = await getQuoteFunction(/* ...params */);
  if(result.data.state === "In Progress"){
    await new Promise(r => setTimeout(r, 10000));
    continue;
  }
  return result;
}

throw new Error("max tries reached");

Doing automated retries for blocks is something the dev team is interested in, however, and we can let you know here if it's included!

Update!

Workflows blocks now support error handling that includes automatic retries :confetti_ball:

Excellent, thanks! I'll still use the current pattern, as what comes back in the case I mentioned above is not an error, but an 'In Progress' result, but I'm sure this will come in handy in other cases that do return error codes.