# Automation definitions

Create, validate and update automation definitions.

Create, validate and update automation definitions.

## Get automation definitions

`GET /v1/automations/definitions/`

Required scope: `automations:write`

### Parameters

| Name | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `after_id` | query | integer | No | min 0 |

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `automations` | object[] | No | read-only |
| `automations[].id` | integer | No | read-only |
| `automations[].is_active` | boolean | No | read-only |
| `automations[].name` | string | No | read-only |
| `next_after_id` | integer \| null | No | read-only |

### Responses

- `200` Success
- `400` The request is invalid.
- `401` Authentication is missing, invalid, or revoked.
- `403` The authenticated identity lacks the required scope or capability.
- `404` The resource is unavailable or not visible to this organization.
- `429` The request-rate budget is exhausted.

```bash
curl -X GET "https://api.themochi.app/v1/automations/definitions/" \
  -H "Authorization: Bearer $MOCHI_API_KEY"
```

## Create automation definitions

`POST /v1/automations/definitions/`

Required scope: `automations:write`

### Parameters

| Name | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string (uuid) | Yes | UUID4 identifying one intended write. Reuse it only when retrying that same write. |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `document` | object | Yes | Canonical automation graph. Read the workspace capabilities endpoint for the enabled node types, fields and limits. |
| `document.channel` | string \| null | No |  |
| `document.entry` | string \| null | No |  |
| `document.id` | integer \| null | No |  |
| `document.is_active` | boolean | No |  |
| `document.layout` | object | No |  |
| `document.name` | string | Yes |  |
| `document.nodes` | object[] | Yes |  |
| `document.public_replies` | object[] | No |  |
| `document.schema_version` | integer | No |  |
| `document.settings` | object | No |  |
| `document.triggers` | object[] | Yes |  |

### Response (201)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `automation_id` | integer | No | read-only |
| `document` | object | No | Canonical automation graph. Read the workspace capabilities endpoint for the enabled node types, fields and limits. |
| `document.channel` | string \| null | No |  |
| `document.entry` | string \| null | No |  |
| `document.id` | integer \| null | No |  |
| `document.is_active` | boolean | No |  |
| `document.layout` | object | No |  |
| `document.name` | string | Yes |  |
| `document.nodes` | object[] | Yes |  |
| `document.public_replies` | object[] | No |  |
| `document.schema_version` | integer | No |  |
| `document.settings` | object | No |  |
| `document.triggers` | object[] | Yes |  |
| `editor_url` | string | No | read-only |
| `etag` | string | No | read-only |
| `flow_preview` | object[] | No | read-only |
| `flow_preview[].description` | string | No | read-only |
| `flow_preview[].title` | string | No | read-only |
| `revision` | integer | No | read-only |

### Responses

- `201` Success
- `400` The request is invalid.
- `401` Authentication is missing, invalid, or revoked.
- `403` The authenticated identity lacks the required scope or capability.
- `404` The resource is unavailable or not visible to this organization.
- `409` The write conflicts with current state or an identical request is still running.
- `422` The write contains fields outside its closed input schema.
- `429` The request-rate budget is exhausted.

```bash
curl -X POST "https://api.themochi.app/v1/automations/definitions/" \
  -H "Authorization: Bearer $MOCHI_API_KEY" \
  -H "Idempotency-Key: $(uuidgen | tr A-Z a-z)" \
  -H "Content-Type: application/json" \
  -d '{"document":{"name":"string","nodes":[{}],"triggers":[{}]}}'
```

## Get automation assets

`GET /v1/automations/definitions/assets/`

Required scope: `automations:write`

### Parameters

| Name | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `query` | query | string | No | max length 255 |

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `links` | object[] | No | read-only |
| `links[].name` | string | No | read-only |
| `links[].url` | string | No | read-only |
| `media` | object[] | No | read-only |
| `media[].file_id` | string | No | read-only |
| `media[].media_kind` | string | No | read-only |
| `media[].name` | string | No | read-only |

### Responses

- `200` Success
- `400` The request is invalid.
- `401` Authentication is missing, invalid, or revoked.
- `403` The authenticated identity lacks the required scope or capability.
- `404` The resource is unavailable or not visible to this organization.
- `429` The request-rate budget is exhausted.

```bash
curl -X GET "https://api.themochi.app/v1/automations/definitions/assets/" \
  -H "Authorization: Bearer $MOCHI_API_KEY"
```

## Get automation capabilities

`GET /v1/automations/definitions/capabilities/`

Required scope: `automations:write`

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `ask` | boolean | No | read-only |
| `audio` | boolean | No | read-only |
| `branching` | boolean | No | read-only |
| `drafts` | boolean | No | read-only |
| `follow_ups` | boolean | No | read-only |
| `format` | string | No | read-only |
| `messenger` | boolean | No | read-only |
| `new_triggers` | boolean | No | read-only |
| `whatsapp` | boolean | No | read-only |

### Responses

- `200` Success
- `400` The request is invalid.
- `401` Authentication is missing, invalid, or revoked.
- `403` The authenticated identity lacks the required scope or capability.
- `404` The resource is unavailable or not visible to this organization.
- `429` The request-rate budget is exhausted.

```bash
curl -X GET "https://api.themochi.app/v1/automations/definitions/capabilities/" \
  -H "Authorization: Bearer $MOCHI_API_KEY"
```

## Validate automation definition

`POST /v1/automations/definitions/validate/`

Required scope: `automations:write`

### Parameters

| Name | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string (uuid) | Yes | UUID4 identifying one intended write. Reuse it only when retrying that same write. |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `automation_id` | integer | No |  |
| `document` | object | Yes | Canonical automation graph. Read the workspace capabilities endpoint for the enabled node types, fields and limits. |
| `document.channel` | string \| null | No |  |
| `document.entry` | string \| null | No |  |
| `document.id` | integer \| null | No |  |
| `document.is_active` | boolean | No |  |
| `document.layout` | object | No |  |
| `document.name` | string | Yes |  |
| `document.nodes` | object[] | Yes |  |
| `document.public_replies` | object[] | No |  |
| `document.schema_version` | integer | No |  |
| `document.settings` | object | No |  |
| `document.triggers` | object[] | Yes |  |

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `valid` | boolean | No | read-only |

### Responses

- `200` Success
- `400` The request is invalid.
- `401` Authentication is missing, invalid, or revoked.
- `403` The authenticated identity lacks the required scope or capability.
- `404` The resource is unavailable or not visible to this organization.
- `409` The write conflicts with current state or an identical request is still running.
- `422` The write contains fields outside its closed input schema.
- `429` The request-rate budget is exhausted.

```bash
curl -X POST "https://api.themochi.app/v1/automations/definitions/validate/" \
  -H "Authorization: Bearer $MOCHI_API_KEY" \
  -H "Idempotency-Key: $(uuidgen | tr A-Z a-z)" \
  -H "Content-Type: application/json" \
  -d '{"document":{"name":"string","nodes":[{}],"triggers":[{}]}}'
```

## Get automation definition

`GET /v1/automations/definitions/{automation_id}/`

Required scope: `automations:write`

### Parameters

| Name | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `automation_id` | path | integer | Yes |  |

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `automation_id` | integer | No | read-only |
| `document` | object | No | Canonical automation graph. Read the workspace capabilities endpoint for the enabled node types, fields and limits. |
| `document.channel` | string \| null | No |  |
| `document.entry` | string \| null | No |  |
| `document.id` | integer \| null | No |  |
| `document.is_active` | boolean | No |  |
| `document.layout` | object | No |  |
| `document.name` | string | Yes |  |
| `document.nodes` | object[] | Yes |  |
| `document.public_replies` | object[] | No |  |
| `document.schema_version` | integer | No |  |
| `document.settings` | object | No |  |
| `document.triggers` | object[] | Yes |  |
| `editor_url` | string | No | read-only |
| `etag` | string | No | read-only |
| `flow_preview` | object[] | No | read-only |
| `flow_preview[].description` | string | No | read-only |
| `flow_preview[].title` | string | No | read-only |
| `revision` | integer | No | read-only |

### Responses

- `200` Success
- `400` The request is invalid.
- `401` Authentication is missing, invalid, or revoked.
- `403` The authenticated identity lacks the required scope or capability.
- `404` The resource is unavailable or not visible to this organization.
- `429` The request-rate budget is exhausted.

```bash
curl -X GET "https://api.themochi.app/v1/automations/definitions/<automation_id>/" \
  -H "Authorization: Bearer $MOCHI_API_KEY"
```

## Set automation definition

`PUT /v1/automations/definitions/{automation_id}/`

Required scope: `automations:write`

### Parameters

| Name | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `automation_id` | path | integer | Yes |  |
| `Idempotency-Key` | header | string (uuid) | Yes | UUID4 identifying one intended write. Reuse it only when retrying that same write. |

### Request body

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `document` | object | Yes | Canonical automation graph. Read the workspace capabilities endpoint for the enabled node types, fields and limits. |
| `document.channel` | string \| null | No |  |
| `document.entry` | string \| null | No |  |
| `document.id` | integer \| null | No |  |
| `document.is_active` | boolean | No |  |
| `document.layout` | object | No |  |
| `document.name` | string | Yes |  |
| `document.nodes` | object[] | Yes |  |
| `document.public_replies` | object[] | No |  |
| `document.schema_version` | integer | No |  |
| `document.settings` | object | No |  |
| `document.triggers` | object[] | Yes |  |
| `etag` | string | Yes | max length 64 |
| `revision` | integer | Yes |  |

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `automation_id` | integer | No | read-only |
| `document` | object | No | Canonical automation graph. Read the workspace capabilities endpoint for the enabled node types, fields and limits. |
| `document.channel` | string \| null | No |  |
| `document.entry` | string \| null | No |  |
| `document.id` | integer \| null | No |  |
| `document.is_active` | boolean | No |  |
| `document.layout` | object | No |  |
| `document.name` | string | Yes |  |
| `document.nodes` | object[] | Yes |  |
| `document.public_replies` | object[] | No |  |
| `document.schema_version` | integer | No |  |
| `document.settings` | object | No |  |
| `document.triggers` | object[] | Yes |  |
| `editor_url` | string | No | read-only |
| `etag` | string | No | read-only |
| `flow_preview` | object[] | No | read-only |
| `flow_preview[].description` | string | No | read-only |
| `flow_preview[].title` | string | No | read-only |
| `revision` | integer | No | read-only |

### Responses

- `200` Success
- `400` The request is invalid.
- `401` Authentication is missing, invalid, or revoked.
- `403` The authenticated identity lacks the required scope or capability.
- `404` The resource is unavailable or not visible to this organization.
- `409` The write conflicts with current state or an identical request is still running.
- `422` The write contains fields outside its closed input schema.
- `429` The request-rate budget is exhausted.

```bash
curl -X PUT "https://api.themochi.app/v1/automations/definitions/<automation_id>/" \
  -H "Authorization: Bearer $MOCHI_API_KEY" \
  -H "Idempotency-Key: $(uuidgen | tr A-Z a-z)" \
  -H "Content-Type: application/json" \
  -d '{"document":{"name":"string","nodes":[{}],"triggers":[{}]},"etag":"string","revision":1}'
```

