Run flows via API
You can execute every flow using API, and the structure of requests stays the same regardless of how internals of a particular flow.
There are basically two requests: one to initiate the flow execution and one to get results. And to perform any requests you need to obtain a secret key
Get the key
Go to API keys section and click the New Server Key button
Pick some comprehensive name for your key, and after the key is generated, make sure you save it somewhere in a safe place, because the key is shown only once and can be retrieved later
Execute the flow
Pick the workflow that you want to run. Go to flow builder and proceed to the Publish tab
Form the request
If you have one Start Node and one End Node form in your workflow, and have already obtained the key, you are all set. You’ll get code snippets which you can use right away — just don’t forget to replace placeholders with your data.
Here’s a breakdown of our example
curl --location '<https://app.scade.pro/api/v1/scade/flow/41785/execute>'
--header 'Authorization: Basic {ACCESS_TOKEN}' \\
--header 'Content-Type: application/json' \\
--data '{
"start_node_id": "axi1-start",
"end_node_id": "AQ6K-end",
"result_node_id": "AQ6K-end",
"node_settings": {
"axi1-start": {
"data": {
"source": {STRING},
"target": {STRING}
}
}
}
}'
https://api.scade.pro/api/v1/scade/flow/<flow_id>/execute
— URL to send your request to. You can get flow_id
from the address bar of your browser
"start_node_id": "SYnn-start"
— the node that should be run first
"end_node_id": "y5iI-end"
— the node that should be run last
"result_node_id": "y5iI-end"
— the node from which results will be extracted; in most cases its id
is the same as the end_node_id
"node_settings": {
"axi1-start": {
"data": {
"sourcе": {STRING},
"target": {STRING}
}
}
}
— it’s a place to put your data into. Replace placeholders like {STRING}
with your actual data (say, URL of some image in this case)
-header 'Authorization: Basic {ACCESS_TOKEN}'
— replace{ACCESS_TOKEN}
with your key. See Get the keysection if needed
Picking other nodes
It’s strongly recommended to have one Start Node Form and one End Node Form. But sometimes flows have more than one of each. In this case you’ll have to go to the Overview on the left sidebar menu ****and from the dropdowns choose which node should be run first and which one should be run last upon your flow execution.
Aside from that, the drill of request formation is the same.
Retrieve task_id
Once you get your request formed, send it using the POST
method. If everything is correct, the response would be like this:
{
"id": 22311,
"data": {
"node_id": null,
"start_node_id": "axi1-start",
"end_node_id": "AQ6K-end",
"result_node_id": "AQ6K-end",
"init_context": {},
"node_settings": {
"SYnn-start": {
"data": {
"image": "<https://example.com/image.jpg>"
}
}
}
},
"status": 2,
"created": "2024-04-18T21:14:34.800001",
"finished": null,
"result": null,
"execution_time": null,
"execution_cost": null,
"parent_id": null,
"ref_id": "flow:1607;",
"task_type": 4,
"is_hide": false,
"public_access_token": null,
"file_result_link": null
}
We need to take "id"
from the response to get the result
Get the result
It’s pretty straightforward. Here’s the url:
https://api.scade.pro/api/v1/task/<task_id>
Replace <task_id>
with the id
that you get upon the flow execution and send a GET
request. Once the flow ends execution, you’ll get the result.
It may take some time, so send requests with intervals between them, and look for the result
object in the response