# Create Workflow

`POST /workflows` · Core · Compute & Automation

Creates a new workflow in the project with a name, trigger type (one of `view_row_event`, `form_submission`, `scheduled`, `manual`, or `webhook`), trigger configuration, and an ordered actions chain of up to 9 action types. Requires the `PROJECT_AUTHOR` role.

Errors:

- `K9O_WORKFLOW_TRIGGER_INVALID` (400) if the `trigger_config` shape is incompatible with the declared `trigger_type`.
- `K9O_WORKFLOW_ACTION_INVALID` (400) if any step in the `actions` chain is malformed or contains a cycle.
- `400 K9O_INVALID_FIELD_VALUE` naming the field, for an invalid expression or timezone.

A `scheduled` trigger's `triggerConfig.scheduleExpression` is standard 5-field cron (values, lists, ranges, steps, month and day names; day-of-week 0-7, Sunday is 0 or 7) or an alias such as `@daily`. It is read in `triggerConfig.timezone` (an IANA name; default UTC). Runs must be at least 5 minutes apart.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | string | yes | The workflow's name, unique in the project. |
| `description` | string | no | What the workflow does. Default empty. |
| `status` | enum ("active", "archived", "draft") | no | `draft` never runs. `active` runs when its trigger fires and must have at least one step. `archived` is kept but never runs. Default `draft`. |
| `triggerType` | enum ("view_row_event", "form_submission", "scheduled", "manual", "webhook") | yes | What starts a run: `manual` (the runs endpoint), `webhook` (a signed HTTP call), `scheduled` (a cron expression) or `form_submission` (an accepted form submission). `view_row_event` is refused. |
| `triggerConfig` | object | yes | The trigger's settings, an object. Its shape depends on `triggerType`: - `manual`: `{}`. - `webhook`: `{signatureScheme?}`; the only scheme is `hmac-sha256`. Don't send a secret: the platform generates one and returns it once, as `webhookSecret`. - `scheduled`: `{scheduleExpression, timezone?}`: a 5-field cron expression or alias, at least 5 minutes apart, read in an IANA time zone (default UTC). - `form_submission`: `{extensionId, formId, collection, statuses?}` for an extension's form, or `{publicationId}` for a published form. |
| `actions` | array of object | yes | The steps, in order: up to 50 at the top level and 100 in all, counting branches. A draft may have none. |
| `actions.[]index` | integer | yes | The step's position in the chain, from 0. |
| `actions.[]action_type` | enum ("write_collection", "read_collection", "invoke_function", "invoke_extension", "llm_inference", "send_notification", "http_request", "approval_step", "branch") | yes | What the step does. |
| `actions.[]config` | object | yes | The step's settings. Their shape depends on `action_type`: - `write_collection`: `{collection, op, payload?, filter?}`. `op` is `insert`, `update` or `delete`; `payload` maps columns to values; `filter` maps columns to `<operator>.<value>` strings, such as `{"id": "eq.{{trigger.id}}"}`. - `read_collection`: `{collection, filter?, select?, order?, limit}`. - `invoke_function`: `{functionName, payload?}`. - `invoke_extension`: `{extensionSlug, action, payload?}`. The payload must fit the action's declared config schema. - `llm_inference`: `{model, prompt, maxTokens?, temperature?}`. - `send_notification`: `{channel, recipient, payload?}`, with `channel` `email` or `webhook`. - `http_request`: `{url, method, headers?, query?, body?}`. A `GET` takes no `body`. - `approval_step`: `{approverResolver, resolverConfig, timeoutSecondsBeforeAutoFail?}`, with `approverResolver` `role`, `group` or `explicit_users`. The run waits for the approvers; a timeout fails the run. - `branch`: `{condition, true_branch, false_branch}`, two nested step lists, up to 3 levels deep. `{{...}}` templates fill values from the trigger and earlier steps; keys, collection names and operators are always literal. |
| `actions.[]retry` | object | no | Retries for a failed step: `{maxAttempts, backoffStrategy?}`, with `maxAttempts` 1 to 10 and `backoffStrategy` `exponential` (default) or `fixed`. Only steps that are safe to repeat accept it. |
| `actions.[]condition` | object | no | A JSON predicate; the step runs only when it holds and is skipped otherwise. Templates may fill its values. |
| `actions.[]parallel` | boolean | no | Run this step at the same time as the adjacent steps that also set it. A step that waits for approval can't be parallel. |
| `rbacBinding` | object | no | Free-form access metadata stored with the workflow and returned as sent. Default `{}`. |

```json
{
  "name": "My Resource",
  "description": "A description",
  "status": "active",
  "triggerType": "view_row_event",
  "triggerConfig": null,
  "actions": [
    {
      "index": 0,
      "action_type": "write_collection",
      "config": null,
      "retry": null
    }
  ]
}
```

## Responses

- **201**: Created

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The workflow as saved, plus `webhookSecret` when this response issued one. |
| `data.id` | string | yes | The workflow id (`wfl_...`). |
| `data.projectId` | string | yes | The project the workflow belongs to (`proj_...`). |
| `data.name` | string | yes | The workflow's name. |
| `data.description` | string | yes | What the workflow does. Empty when none was given. |
| `data.status` | enum ("active", "archived", "draft") | yes | `draft` never runs. `active` runs when its trigger fires and must have at least one step. `archived` is kept but never runs. |
| `data.triggerType` | enum ("view_row_event", "form_submission", "scheduled", "manual", "webhook") | yes | What starts a run. |
| `data.triggerConfig` | object | yes | The trigger's settings, an object. Its shape depends on `triggerType`: - `manual`: `{}`. - `webhook`: `{signatureScheme?}`; the only scheme is `hmac-sha256`. Don't send a secret: the platform generates one and returns it once, as `webhookSecret`. - `scheduled`: `{scheduleExpression, timezone?}`: a 5-field cron expression or alias, at least 5 minutes apart, read in an IANA time zone (default UTC). - `form_submission`: `{extensionId, formId, collection, statuses?}` for an extension's form, or `{publicationId}` for a published form. The webhook signing secret is never part of it. |
| `data.actions` | array of object | yes | The steps, in order. |
| `data.actions.[]index` | integer | yes | The step's position in the chain, from 0. |
| `data.actions.[]action_type` | string | yes | What the step does: `write_collection`, `read_collection`, `invoke_function`, `invoke_extension`, `llm_inference`, `send_notification`, `http_request`, `approval_step` or `branch`. |
| `data.actions.[]config` | object | yes | The step's settings. Their shape depends on `action_type`: - `write_collection`: `{collection, op, payload?, filter?}`. `op` is `insert`, `update` or `delete`; `payload` maps columns to values; `filter` maps columns to `<operator>.<value>` strings, such as `{"id": "eq.{{trigger.id}}"}`. - `read_collection`: `{collection, filter?, select?, order?, limit}`. - `invoke_function`: `{functionName, payload?}`. - `invoke_extension`: `{extensionSlug, action, payload?}`. The payload must fit the action's declared config schema. - `llm_inference`: `{model, prompt, maxTokens?, temperature?}`. - `send_notification`: `{channel, recipient, payload?}`, with `channel` `email` or `webhook`. - `http_request`: `{url, method, headers?, query?, body?}`. A `GET` takes no `body`. - `approval_step`: `{approverResolver, resolverConfig, timeoutSecondsBeforeAutoFail?}`, with `approverResolver` `role`, `group` or `explicit_users`. The run waits for the approvers; a timeout fails the run. - `branch`: `{condition, true_branch, false_branch}`, two nested step lists, up to 3 levels deep. `{{...}}` templates fill values from the trigger and earlier steps; keys, collection names and operators are always literal. |
| `data.actions.[]retry` | object | no | The step's retry settings, `{maxAttempts, backoffStrategy?}`, when set. |
| `data.actions.[]condition` | object | no | The predicate that decides whether the step runs, when set. |
| `data.actions.[]parallel` | boolean | no | Whether the step runs alongside adjacent parallel steps, when set. |
| `data.rbacBinding` | object | yes | Free-form access metadata stored with the workflow and returned as sent. Default `{}`. |
| `data.authoredBy` | string | yes | Who created the workflow (`usr_...`). |
| `data.authoredAt` | string (date-time) | yes | When the workflow was created. |
| `data.updatedBy` | string | yes | Who last changed the workflow (`usr_...`). |
| `data.updatedAt` | string (date-time) | yes | When the workflow last changed. |
| `data.webhookSecret` | string | no | The webhook signing secret (`whsec_...`). Present only in the response that issued it: creating a `webhook` workflow, or changing one to `webhook`. Store it now; it is never shown again. |
| `meta` | object | yes |  |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_INVALID_CREDENTIALS` | The request was made without a valid session or bearer token. |
| 401 | `K9O_SESSION_EXPIRED` | Your session has expired; re-authenticate and retry. |
| 403 | `K9O_ACCESS_DENIED` | Creating a workflow requires the PROJECT_AUTHOR role; your current role does not grant it. |
| 400 | `K9O_WORKFLOW_TRIGGER_INVALID` | The trigger_config shape is invalid for the declared trigger_type — required fields are missing or the configuration is malformed. |
| 400 | `K9O_WORKFLOW_ACTION_INVALID` | The actions chain is malformed — actions is not an array, or a step names an unknown action type. |
| 400 | `K9O_INVALID_FIELD_VALUE` | A scheduled trigger's `scheduleExpression` is not valid cron, or runs less than 5 minutes apart (field schedule_expression), or its `timezone` is not an IANA name (field triggerConfig.timezone). |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/workflows' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "My Resource",
  "description": "A description",
  "status": "active",
  "triggerType": "view_row_event",
  "triggerConfig": null,
  "actions": [
    {
      "index": 0,
      "action_type": "write_collection",
      "config": null,
      "retry": null
    }
  ]
}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/workflows', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
  "name": "My Resource",
  "description": "A description",
  "status": "active",
  "triggerType": "view_row_event",
  "triggerConfig": null,
  "actions": [
    {
      "index": 0,
      "action_type": "write_collection",
      "config": null,
      "retry": null
    }
  ]
}),
});
const { data, meta } = await res.json();
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.studio.workflows.create({
  name: 'My Resource',
  description: 'A description',
  status: 'active',
  triggerType: 'view_row_event',
  triggerConfig: null,
  actions: [{
    index: 0,
    action_type: 'write_collection',
    config: null,
    retry: null
  }]
})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.studio.workflows.create({
    "name": "My Resource",
    "description": "A description",
    "status": "active",
    "triggerType": "view_row_event",
    "triggerConfig": None,
    "actions": [{
        "index": 0,
        "action_type": "write_collection",
        "config": None,
        "retry": None
    }]
})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.Studio.Workflows.Create(ctx, map[string]any{"name": "My Resource", "description": "A description", "status": "active", "triggerType": "view_row_event", "triggerConfig": nil, "actions": []any{map[string]any{"index": 0, "action_type": "write_collection", "config": nil, "retry": nil}}})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.studio.workflows.create(json!({"name": "My Resource", "description": "A description", "status": "active", "triggerType": "view_row_event", "triggerConfig": null, "actions": [json!({"index": 0, "action_type": "write_collection", "config": null, "retry": null})]})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.studio().workflows().create(Map.of("name", "My Resource", "description", "A description", "status", "active", "triggerType", "view_row_event", "triggerConfig", null, "actions", List.of(Map.of("index", 0, "action_type", "write_collection", "config", null, "retry", null))))
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.Studio.Workflows.CreateAsync(new Dictionary<string, object> { ["name"] = "My Resource", ["description"] = "A description", ["status"] = "active", ["triggerType"] = "view_row_event", ["triggerConfig"] = null, ["actions"] = new object[] { new Dictionary<string, object> { ["index"] = 0, ["action_type"] = "write_collection", ["config"] = null, ["retry"] = null } } })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.studio.workflows.create({ name: "My Resource", description: "A description", status: "active", triggerType: "view_row_event", triggerConfig: nil, actions: [{ index: 0, action_type: "write_collection", config: nil, retry: nil }] })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->studio->workflows->create(['name' => 'My Resource', 'description' => 'A description', 'status' => 'active', 'triggerType' => 'view_row_event', 'triggerConfig' => null, 'actions' => [['index' => 0, 'action_type' => 'write_collection', 'config' => null, 'retry' => null]]])
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/create-workflow
