# Update workflow

> Source: https://truto.one/docs/api-reference/admin/workflows/update/

`PATCH /workflow/{id}`

Resource: **Workflows**

Updates a workflow's trigger or config. The body can be JSON or YAML. A `config` sent replaces the stored one.

## Path parameters

- **`id`** _(string, required)_

## Request body

- **`trigger_name`** _(string)_
  The event that runs the workflow. `integrated_account:active` runs when an integrated account becomes active (for example right after it is connected); `unified_webhook:batch` runs when a batch of unified webhook events arrives.
  Allowed: `integrated_account:active`, `unified_webhook:batch`
- **`config`** _(object, required)_
  Workflow execution configuration.
  - **`run_if`** _(string)_
    JSONata condition evaluated before executing workflow steps.
  - **`steps`** _(array<object>)_
    - **`type`** _(string)_
      Step execution type.
      Allowed: `run`
    - **`action`** _(string)_
      Action executed by the step. `run_sync_job` is the only action.
      Allowed: `run_sync_job`
    - **`run_if`** _(string)_
      JSONata condition; the step is skipped when it is falsy.
    - **`cron_expression`** _(string)_
      Optional cron expression for scheduled execution, in UTC. When set, the step creates a sync job cron trigger instead of starting a run, so the trigger's check applies: the step fails if the expression doesn't parse or its next two runs are less than 5 minutes apart.
    - **`config`** _(string | object)_
      A JSONata expression that returns the step's payload, or an object whose values may use `{{placeholders}}`. For `run_sync_job` it must give a `sync_job_id`.
- **`change_message`** _(string)_
  Why this change is being made. Optional, at most 2000 characters, recorded with the version this save creates (see `GET /workflow/{id}/versions`). Not saved on the workflow.

## Response body

- **`id`** _(string)_
  The ID of the workflow.
- **`environment_id`** _(string)_
  The environment the workflow belongs to.
- **`trigger_name`** _(string)_
  The event that runs the workflow. `integrated_account:active` runs when an integrated account becomes active (for example right after it is connected); `unified_webhook:batch` runs when a batch of unified webhook events arrives.
  Allowed: `integrated_account:active`, `unified_webhook:batch`
- **`config`** _(object, required)_
  Workflow execution configuration.
  - **`run_if`** _(string)_
    JSONata condition evaluated before executing workflow steps.
  - **`steps`** _(array<object>)_
    - **`type`** _(string)_
      Step execution type.
      Allowed: `run`
    - **`action`** _(string)_
      Action executed by the step. `run_sync_job` is the only action.
      Allowed: `run_sync_job`
    - **`run_if`** _(string)_
      JSONata condition; the step is skipped when it is falsy.
    - **`cron_expression`** _(string)_
      Optional cron expression for scheduled execution, in UTC. When set, the step creates a sync job cron trigger instead of starting a run, so the trigger's check applies: the step fails if the expression doesn't parse or its next two runs are less than 5 minutes apart.
    - **`config`** _(string | object)_
      A JSONata expression that returns the step's payload, or an object whose values may use `{{placeholders}}`. For `run_sync_job` it must give a `sync_job_id`.
- **`created_at`** _(string)_
  When the workflow was created.
- **`updated_at`** _(string)_
  When the workflow was last updated.

## Errors

| Status | Description |
| :----- | :---------- |
| `400` | The body is not valid JSON or YAML, the config is invalid, or `change_message` is not a string or is too long. |
| `404` | Workflow not found |

## Code examples

### curl

```bash
curl -X PATCH 'https://api.truto.one/workflow/{id}' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "trigger_name": "integrated_account:active",
  "config": {},
  "change_message": "your_change_message"
}'
```

### JavaScript

```javascript
const body = {
  "trigger_name": "integrated_account:active",
  "config": {},
  "change_message": "your_change_message"
};

const response = await fetch('https://api.truto.one/workflow/{id}', {
  method: 'PATCH',
  headers: {
    'Authorization': 'Bearer <your_api_token>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

url = "https://api.truto.one/workflow/{id}"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "trigger_name": "integrated_account:active",
    "config": {},
    "change_message": "your_change_message"
}

response = requests.patch(url, headers=headers, params=params, json=payload)
print(response.json())
```
