# Create workflow

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

`POST /workflow`

Resource: **Workflows**

## Request body

- **`id`** _(string)_
  Optional workflow ID. If not provided, it will be generated.
- **`environment_id`** _(string)_
  The environment in which this workflow is created.
- **`trigger_name`** _(string)_
  The event that triggers this workflow.
- **`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.
    - **`cron_expression`** _(string)_
      Optional cron expression for scheduled execution.
    - **`config`** _(string)_
      JSONata expression evaluated at runtime to generate the step execution payload.

## Response body

- **`id`** _(string)_
- **`environment_id`** _(string)_
- **`trigger_name`** _(string)_
- **`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.
    - **`cron_expression`** _(string)_
      Optional cron expression for scheduled execution.
    - **`config`** _(string)_
      JSONata expression evaluated at runtime to generate the step execution payload.
- **`created_at`** _(string)_
- **`updated_at`** _(string)_

## Code examples

### curl

```bash
curl -X POST 'https://api.truto.one/workflow' \
  -H 'Authorization: Bearer <your_api_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "id": "4a4de828-f4c9-4bea-8ef4-2d705aec43bc",
  "environment_id": "05daecaf-4365-42e8-8370-8127de5dd717",
  "trigger_name": "integrated_account:connected",
  "config": {}
}'
```

### JavaScript

```javascript
const body = {
  "id": "4a4de828-f4c9-4bea-8ef4-2d705aec43bc",
  "environment_id": "05daecaf-4365-42e8-8370-8127de5dd717",
  "trigger_name": "integrated_account:connected",
  "config": {}
};

const response = await fetch('https://api.truto.one/workflow', {
  method: 'POST',
  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"
headers = {
    "Authorization": "Bearer <your_api_token>",
    "Content-Type": "application/json",
}
params = {
}
payload = {
    "id": "4a4de828-f4c9-4bea-8ef4-2d705aec43bc",
    "environment_id": "05daecaf-4365-42e8-8370-8127de5dd717",
    "trigger_name": "integrated_account:connected",
    "config": {}
}

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

### Truto TS SDK

```typescript
import Truto from '@truto/truto-ts-sdk';

const truto = new Truto({
  token: '<your_api_token>',
});

const body = {
  "id": "4a4de828-f4c9-4bea-8ef4-2d705aec43bc",
  "environment_id": "05daecaf-4365-42e8-8370-8127de5dd717",
  "trigger_name": "integrated_account:connected",
  "config": {}
};

const result = await truto.workflow.create(body);

console.log(result);
```

### Truto Python SDK

```python
import asyncio
from truto_python_sdk import TrutoApi

truto_api = TrutoApi(token="<your_api_token>")

async def main():
    body = {
        "id": "4a4de828-f4c9-4bea-8ef4-2d705aec43bc",
        "environment_id": "05daecaf-4365-42e8-8370-8127de5dd717",
        "trigger_name": "integrated_account:connected",
        "config": {}
    }

    result = await truto_api.workflows.create(body)
    print(result)

asyncio.run(main())
```
