Skip to content

Creating a Workflow

A Workflow lets you automatically run actions in response to events in Truto. Instead of manually reacting to webhook events, workflows allow you to declaratively define when something should happen and what should be executed.

Workflows are environment-specific and are triggered by system events such as Integrated Account lifecycle events, or incoming webhooks.

A Workflow first needs a trigger on which it should run.

Prerequisites

Before creating a workflow, make sure you have:

  • An Environment
  • A Webhook (to receive Sync Job events or downstream data)
  • A Sync Job (Currently Workflow supports only Sync Job Runs)
  • An Integrated Account (for integrations like Zendesk, Salesforce, etc.)

For creating Webhook - Refer Webhook Guide Reference for more details about the requests. For creating Sync Job - Refer Sync Job Guide Reference for more details about the requests.

Workflow triggers

A trigger represents an event emitted by Truto. Common examples include:

  • integrated_account:active (Truto supports only one trigger for workflows)

Creating a Workflow

Use the following request to create a workflow config,

bash
curl --location 'https://api.truto.one/workflow' \
--header 'Authorization: Bearer <api_token>' \
--header 'Content-Type: application/json' \
--data '{
    "label": "Run sync job on account connection",
    "trigger_name": "integrated_account:active",
    "config": {
        "run_if": "integration.name = '\''calcom'\''",
        "steps": [
            {
                "type": "run",
                "action": "run_sync_job",
                "config": "(\n  $sync_job_id := $mapValues(integration.name,{\n    \"calcom\": \"51b79ace-a7b4-4077-93ba-8048a06ece2b\"\n  });\n  {\n    \"sync_job_id\": $sync_job_id,\n    \"integrated_account_id\": integrated_account_id,\n    \"webhook_id\": \"9fda519d-148f-4cc5-bbac-4e373b16e5d4\"\n  }\n)"
            }
        ]
    }
}'

This request does supports yaml for the body.

Creating a Workflow with Cron Expression

Use the following request to create a workflow config,

bash
curl --location 'https://api.truto.one/workflow' \
--header 'Authorization: Bearer <api_token>' \
--header 'Content-Type: application/json' \
--data '{
  "label": "Run sync job on account connection",
  "trigger_name": "integrated_account:connected",
  "config": {
    "run_if": "integration.name = '\''calcom'\''",
    "steps": [
      {
        "type": "run",
        "action": "run_sync_job",
        "cron_expression": "0 */6 * * *",
        "config": "(
          $sync_job_id := $mapValues(integration.name,{
            \"calcom\": \"51b79ace-a7b4-4077-93ba-8048a06ece2b\"
          });
          {
            \"sync_job_id\": $sync_job_id,
            \"integrated_account_id\": integrated_account_id,
            \"webhook_id\": \"9fda519d-148f-4cc5-bbac-4e373b16e5d4\"
          }
        )"
      }
    ]
  }
}'

This request does supports yaml for the body.

Workflow API Reference

Refer Workflow API Reference for more details about the requests.