Skip to main content
Run flows via API
Updated over 3 weeks ago

You can execute every flow using API, and the structure of requests stays the same regardless of a particular flow internals.

There are basically two requests: one to initiate the flow execution and another one to get results. And to perform any requests you need to obtain a secret key.

Get the key

Go to the API & credentials section, click the Generate Server key button.

Choose 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't be retrieved later.

Execute the flow

Pick the workflow that you want to run. Go to Workflow builder and proceed to the Publish button.

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://api.scade.pro/api/v1/scade/flow/1607/execute' \
--header 'Authorization: Basic {ACCESS_TOKEN}' \
--header 'Content-Type: application/json' \
--data '{
"start_node_id": "SYnn-start",
"end_node_id": "y5iI-end",
"result_node_id": "y5iI-end",
"node_settings": {
"SYnn-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": {
"SYnn-start": {
"data": {
"source": {STRING},
"target": {STRING}
}
}
}

— it's a place to put your data into. Replace placeholders like {STRING} with your actual data (say, URLs of a video and an image in this case)

--header 'Authorization: Basic {ACCESS_TOKEN}' — replace {ACCESS_TOKEN} with your key. See Get the key section if needed.

Picking other nodes

It’s strongly recommended to have one Start Node and one End Node. But there is an option to chose any node from your workflow. 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": "SYnn-start",
"end_node_id": "y5iI-end",
"result_node_id": "y5iI-end",
"init_context": {},
"node_settings": {
"SYnn-start": {
"data": {
"source": "https://example.com/video.mp4",
"target": "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

Did this answer your question?