Workflows
A workflow starts a sync job run for you when something happens in your environment: an integrated account finishes connecting, or Truto processes a batch of webhook events from the account's app. Use one to start a V4 sync job for every customer that connects, without a webhook handler in your app that catches integrated_account:active and calls POST /sync-job-run.
Skip the reading — fast path for coding agents
truto workflows list -o json
/skill truto-jsonata
Workflows have no screen in the dashboard. Create and manage them with the API, the CLI or an SDK.
Workflows at a glance
| Triggers | integrated_account:active and unified_webhook:batch |
| What a step does | run_sync_job: starts one sync job run, or creates a schedule when the step has a cron_expression |
| Conditions | A JSONata run_if on the workflow and on each step |
| Step order | In order, one at a time |
| Retries | A failed run is retried, and each retry runs every step again |
| Run statuses | created, running, completed, failed |
| Starting a run by hand | Not possible: only the trigger starts a run |
| History | Every update saves a version you can restore |
A workflow has one action, run_sync_job. Fetching, filtering, transforming and sending data all happen in the sync job it starts; see the V4 sync job reference.
When does a workflow run?
A workflow has a trigger_name and a config:
- When the trigger fires in the workflow's environment, Truto evaluates the workflow's
run_if. If it's falsy, nothing else happens. - Otherwise Truto creates a workflow run and runs the steps in order, one at a time. A step with its own
run_ifthat evaluates falsy is skipped. A step that fails doesn't stop the ones after it; the run then endsfailed. - The run ends
completed, orfailedif any step failed. A completed run'sresultlists each step withsuccess, anderrororresult.
Every workflow in the environment with the same trigger runs, each with its own run.
Which triggers start a workflow?
trigger_name |
Fires when |
|---|---|
integrated_account:active |
An integrated account finishes connecting through a link or the connection flow: its post-install and validation actions passed and it has no post-connect form left to fill in. It fires again when an existing account reconnects. |
unified_webhook:batch |
Truto processed a batch of inbound vendor webhook events for an account into record:* events. Runs are delivered at least once, and webhook.batch can group an account's events into fewer runs. See Receiving vendor webhooks and Batching vendor webhook events. |
The workflow's run_if and its steps see integrated_account_id, environment_id, integration (the account's integration, with integration.name), context (the account's context) and tenant_id. Steps also see payload, the trigger's data: for unified_webhook:batch that's integrated_account_id, events and batch_size.
Creating a workflow with any other trigger_name returns 404.
What does a workflow step do?
config.steps is an array. Each step has type: "run" and action: "run_sync_job", which is the one action there is.
| Field | What it does |
|---|---|
config |
The body of the sync job run to create, as an object with {{placeholders}} or a JSONata string that returns it. It must include sync_job_id. The rest is what POST /sync-job-run takes: integrated_account_id and a webhook_id, super_query or daemon_group_key for runtime versions 1 to 3, or args for version 4. A datastore_id makes the step fail with 400: to write to a datastore, use a version 4 sync job and name the datastore in args. |
cron_expression |
Instead of running the sync job once, create a schedule for it with this cron expression. The step's config becomes the schedule's body. |
run_if |
A JSONata expression. The step runs only when it's truthy. |
A run created by a step sends sync_job_run:created to your webhooks, like any other run.
Example: run a sync job when an account connects
This workflow runs a V4 sync job for every HubSpot or Salesforce account that connects, and sends the output to one webhook.
curl -X POST "https://api.truto.one/workflow" \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{
"trigger_name": "integrated_account:active",
"config": {
"run_if": "integration.name in [\"hubspot\", \"salesforce\"]",
"steps": [
{
"type": "run",
"action": "run_sync_job",
"config": "{ \"sync_job_id\": \"<sync_job_id>\", \"args\": { \"integrated_account_id\": integrated_account_id, \"webhook_id\": \"<webhook_id>\" } }"
}
]
}
}'truto workflows create -b '{
"trigger_name": "integrated_account:active",
"config": {
"run_if": "integration.name in [\"hubspot\", \"salesforce\"]",
"steps": [
{
"type": "run",
"action": "run_sync_job",
"config": "{ \"sync_job_id\": \"<sync_job_id>\", \"args\": { \"integrated_account_id\": integrated_account_id, \"webhook_id\": \"<webhook_id>\" } }"
}
]
}
}'import TrutoApi from '@truto/truto-ts-sdk'
const trutoApi = new TrutoApi({ token: process.env.TRUTO_API_TOKEN })
const workflow = await trutoApi.workflow.create({
trigger_name: 'integrated_account:active',
config: {
run_if: 'integration.name in ["hubspot", "salesforce"]',
steps: [
{
type: 'run',
action: 'run_sync_job',
config:
'{ "sync_job_id": "<sync_job_id>", "args": { "integrated_account_id": integrated_account_id, "webhook_id": "<webhook_id>" } }',
},
],
},
})import os
from truto_python_sdk import TrutoApi
truto_api = TrutoApi(token=os.environ["TRUTO_API_TOKEN"])
workflow = await truto_api.workflows.create({
"trigger_name": "integrated_account:active",
"config": {
"run_if": 'integration.name in ["hubspot", "salesforce"]',
"steps": [
{
"type": "run",
"action": "run_sync_job",
"config": '{ "sync_job_id": "<sync_job_id>", "args": { "integrated_account_id": integrated_account_id, "webhook_id": "<webhook_id>" } }',
}
],
},
})The step's config is a JSONata string, so integrated_account_id is read from the trigger. To pick a different sync job per integration, map on integration.name:
(
$sync_job_id := $lookup({
"hubspot": "<hubspot_sync_job_id>",
"salesforce": "<salesforce_sync_job_id>"
}, integration.name);
{
"sync_job_id": $sync_job_id,
"args": {
"integrated_account_id": integrated_account_id,
"webhook_id": "<webhook_id>"
}
}
)To keep the account in sync after the first run, add "cron_expression": "0 */6 * * *" to the step. The workflow then creates a schedule for the account instead of a single run. Schedules run in UTC, at most every five minutes.
How do I see what a workflow did?
GET /workflow-run?workflow_id=<id> lists a workflow's runs. Filter by status: created, running, completed or failed. A completed run's result.steps says which steps ran and which were skipped. A skipped step has success: true and error: "Step skipped: run_if evaluated to false". A run that ends failed keeps only a generic result.error.
curl "https://api.truto.one/workflow-run?workflow_id=<workflow_id>&status=failed" \
-H "Authorization: Bearer <API token>"truto workflow-runs list --workflow-id <workflow_id> --status failedconst runs = await trutoApi.workflowRun
.list({ workflow_id: '<workflow_id>', status: 'failed' })
.toArray()runs = await truto_api.workflow_runs.list(
workflow_id="<workflow_id>", status="failed"
).to_array()Truto retries a failed run, and each retry runs every step again. A failed step doesn't stop the steps after it, so a step that already created a sync job run can create another on the retry. Keep steps that can't run twice out of workflows whose other steps may fail. You can't start a workflow run yourself: only its trigger does.
How do I undo a change to a workflow?
Each update to a workflow saves a version of its trigger_name and config. GET /workflow/{id}/versions lists them, and POST /workflow/{id}/versions/{version}/restore makes an earlier one current again, saved as a new version. Add change_message (up to 2,000 characters) to a PATCH or a restore to record why.
# List the workflow's versions
curl "https://api.truto.one/workflow/<workflow_id>/versions" \
-H "Authorization: Bearer <API token>"
# Make version 3 current again
curl -X POST "https://api.truto.one/workflow/<workflow_id>/versions/3/restore" \
-H "Authorization: Bearer <API token>" \
-H "Content-Type: application/json" \
-d '{ "change_message": "Back to the HubSpot-only trigger" }'A restore returns 400 when that version matches the current configuration. Pass expected_current_version to have it return 409 if someone else changed the workflow since you read its versions.
Next
The full set of endpoints is in the Workflows and Workflow runs API references. Write the sync job a step starts with the V4 sync job reference, and send its output to your webhook or a datastore. For how runs and events work across runtime versions, see the RapidBridge overview.