How to write API Action "On Done => do x" in App Flow

In API Actions on the page there is a dynamic event called “On Done”. Is there something similar for API Actions in App Flow

You cannot do that. That’s not how flows work.
All steps are sequentially executed, but they don’t necessarily wait for the previous step to return a value.

Since this is aysnc, the API step is assumed completed once the API call is made… and flow moves on to the next step.

You can configure the API step on page, and then on its dynamic success/done event call the page/app flow.

1 Like

sync* (synchronous)

You can add an if condition, if the response of the API Action what you want, you add a Response step to return what you want

OR

You would declare a variable “guard” before the While loop, initially set to true, and make While use that variable. Once you want to break out of the loop, you set this variable to false, so the While won’t get executed again. And then, outside of the loop, you Set Value or Response whatever you want

And you should also have a Delay step inside your While loop

1 Like

No, I meant async. The API step is async. Syncronous would mean the flow would wait for a response from this step before moving on to the next one, but that is not the case here.

Using an infinite While with a flag is an option, but not a code-maintenance-friendly solution in my opinion.

Edit: Yup, my bad, I apologize for any confusion. Didn’t know this (App Flow) was thing, it’s clear I’m a back-end person only :sweat_smile:

I was thinking this was on server-side - where API Action is synchronous

1 Like

In the backend they are also async(for nodejs).
But they run sequentially if that is what you mean.
Only server-side formatters are sync.

All steps are sequentially executed, but they don’t necessarily wait for the previous step to return a value.

Since this is aysnc, the API step is assumed completed once the API call is made… and flow moves on to the next step.

This had not come to my attention before – that a call for an action in an API Flow just moves on without waiting for any values to be returned!

In fact, that should be a key Caveat mentioned in the existing Flow Docs. Certainly the Forums here contain quite a few reports of unexpected problems because an external API call did NOT return values “on time”. Just traffic, latency, overload on resources, every day internet outages for 1001 reasons

In fact, I have been “assuming” too much in my API calls.

The Conditionals should have been there the whole time because I’m executing several separate queries that need to have returned values before calling the next page.

I’ve been lucky so far because my database is on the same server ip & the queries have returned “on time”. But this post tells me I should routinely add more components to deal with all “unexpected or empty or timed-out queries” even on server-side API flows. I’ve been lazy because so far the query returns have worked well without those conditionals. But my “tests” are certainly not stressing the server-side.

Just a clarification here.
Actually the flow steps are executed sequentially.

The only exception is the Run step, which executes an external action and it goes its own asynchronous way.

Server Actions (aka API Actions) are also executed sequentially and each step waits for the previous one to complete.

3 Likes

Introduction to App Connect Flow

???

the Flow Actions are executed synchronous after each other.
So this means each action step runs only when the previous COMPLETES.

I just found this and posted at the same time –

I wrote a simple API that waits 5 seconds before returning a status code 210. The App Flow did wait for this API to complete before moving on to the next step. I also then turned off my API . Then the App Flow correctly returned a 404 status before moving on to the next step.

New information. Did not know that. Thanks.

So looks like @ruast you need to change the solution on this post.
And as I see you have tested, it works as you want. :slight_smile:

1 Like

Done :slight_smile:

It should have been Teodor’s post. But its fine. :slight_smile:

But that’s what i did… Teodor’s post is the solution

I saw yours marked earlier. Now its Teodor’s. All good. :grinning:

1 Like

Just some more tests :

An action scheduler that calls a page flow or app flow or api action does not seem to wait for any of these to complete before running the next schedule , that is it always runs on the schedule. So if an action scheduler tick event is like this :

image

Here step 3 will not wait for step 2 to complete because this is Action and not an inline flow
i.e I guess it’s actually just a set of run actions and hence async , if we convert it to flow it looks like this image and is therefore async.

If we turn it into a flow that does not use Run step like this : Then the third step is async but because the action scheduler will not wait for the api to complete, it will keep running the first step on schedule
The third step will only run after API is complete
image

However in an action scheduler where the only action is to call an App flow, or a Page Flow, the App flow / Page Flow will wait for the API’s within it to complete and only then will it run again, even if the scehduler calls it , it only runs again after all the steps including the API step are complete

This seems to be perfect for running sitewide background tasks, except that I don’t know how to set session variables from App Flow :frowning: Made a separate thread for that. Hope there is a way.

So in summary it seems that to have actions that run on schedule but where the steps are completed and wait for previous step ,before the next possible schedule is run, it is possible to do that by moving all the steps to an app flow or page flow and then only using the scheduler to call that app flow or page flow rather than have it run any steps itself.