Is it possible to execute an Action synchronously with the API?

api

(Giorgos Karagkounis) #1

I would like to execute an action and wait for the result using the REST API. Is that possible?


Is the StackStorm python client execution action asynchronous? How to be asynchronous?
(Eugen C.) #2

It’s possible to trigger an action execution via the API, check POST /api/v1/executions endpoint https://api.stackstorm.com/api/v1/executions/#/action_executions_controller.post

You have to poll however for action completion, having the id returned from the previous POST (create execution) request.


If you’ll try st2 run, - it has the same polling logic. For example:

st2 --debug run core.local 'sleep 10'

With the debug flag set, - it will show exactly which API requests st2client made, including polling for action completion.

You can re-use API requests from this command, - it’ll help you to bootstrap faster having the examples.


(Giorgos Karagkounis) #3

I guess this is not called synchronously but thank you for the answer!


(Eugen C.) #4

Yes, that’s the only way to do it.

API can’t synchronously block and wait for Action to complete until it’s finished, - instead it just returns an execution id immediately that was triggered.
For example, what if action/workflow is running for hours/days? The response won’t survive the http/timeouts and won’t be delivered, if we talk about typical API call.

Hence, async.


BTW, there is an event stream one could listen on: https://api.stackstorm.com/stream/v1/stream/#/stream_controller.get_all for different events happening in the platform, incl. executions completion.


(jaf) #5

Hi,
and what’s about using sensors, I mean, could we get a sync response using sensors (passive mode)? If no, how would sensor response be? I mean, an empty response like with webhooks or we would get an execution id like /v1/executions API

Thanks