# Flows

List flows and start flow runs.

List flows and start flow runs.

## List flows

`GET /v1/flows/`

Required scope: `automations:write`

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `data` | object[] | Yes |  |
| `data[].channel` | string | No | read-only |
| `data[].created_at` | string (date-time) | No | read-only |
| `data[].id` | string | No | read-only |
| `data[].is_active` | boolean | No | read-only |
| `data[].name` | string | No | read-only |
| `data[].step_count` | integer | No | read-only |
| `data[].updated_at` | string (date-time) | No | read-only |
| `next_cursor` | string \| null | Yes |  |

### 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/flows/" \
  -H "Authorization: Bearer $MOCHI_API_KEY"
```

## Create flow

`POST /v1/flows/`

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 |
| --- | --- | --- | --- |
| `channel` | string | No | one of `INSTAGRAM`, `WHATSAPP`, `MESSENGER` |
| `is_active` | boolean | Yes |  |
| `name` | string | Yes | max length 255 |
| `steps` | any \| any \| object \| object \| object \| object \| object \| object \| object \| object \| object[] | Yes | A bounded DAG: maximum depth 3 and at most 10 send steps. Step ids and targets form the graph.; max 20 items; min 1 items |

### Response (201)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `channel` | string | No | read-only |
| `created_at` | string (date-time) | No | read-only |
| `id` | string | No | read-only |
| `is_active` | boolean | No | read-only |
| `name` | string | No | read-only |
| `step_count` | integer | No | read-only |
| `updated_at` | string (date-time) | 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/flows/" \
  -H "Authorization: Bearer $MOCHI_API_KEY" \
  -H "Idempotency-Key: $(uuidgen | tr A-Z a-z)" \
  -H "Content-Type: application/json" \
  -d '{"is_active":true,"name":"string","steps":["string"]}'
```

## Get flow run

`GET /v1/flows/runs/{run_id}/`

Required scope: `automations:write`

### Parameters

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

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `created_at` | string (date-time) | No | read-only |
| `current_step` | string | No | read-only |
| `event_counts` | object | No | read-only |
| `event_counts.claimed` | integer | No | read-only |
| `event_counts.failed` | integer | No | read-only |
| `event_counts.paused` | integer | No | read-only |
| `event_counts.succeeded` | integer | No | read-only |
| `finished_at` | string (date-time) \| null | No | read-only |
| `flow_id` | string | No | read-only |
| `lead_id` | string | No | read-only |
| `next_wake_at` | string (date-time) \| null | No | read-only |
| `run_id` | string | No | read-only |
| `state` | string | No | read-only |
| `updated_at` | string (date-time) | 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/flows/runs/<run_id>/" \
  -H "Authorization: Bearer $MOCHI_API_KEY"
```

## Get flow

`GET /v1/flows/{flow_id}/`

Required scope: `automations:write`

### Parameters

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

### Response (200)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `channel` | string | No | read-only |
| `created_at` | string (date-time) | No | read-only |
| `id` | string | No | read-only |
| `is_active` | boolean | No | read-only |
| `name` | string | No | read-only |
| `step_count` | integer | No | read-only |
| `updated_at` | string (date-time) | 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/flows/<flow_id>/" \
  -H "Authorization: Bearer $MOCHI_API_KEY"
```

## Create flow run

`POST /v1/flows/{flow_id}/runs/`

Required scope: `automations:write`

### Parameters

| Name | In | Type | Required | Notes |
| --- | --- | --- | --- | --- |
| `flow_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 |
| --- | --- | --- | --- |
| `lead_id` | integer | Yes |  |

### Response (201)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `created_at` | string (date-time) | No | read-only |
| `current_step` | string | No | read-only |
| `event_counts` | object | No | read-only |
| `event_counts.claimed` | integer | No | read-only |
| `event_counts.failed` | integer | No | read-only |
| `event_counts.paused` | integer | No | read-only |
| `event_counts.succeeded` | integer | No | read-only |
| `finished_at` | string (date-time) \| null | No | read-only |
| `flow_id` | string | No | read-only |
| `lead_id` | string | No | read-only |
| `next_wake_at` | string (date-time) \| null | No | read-only |
| `run_id` | string | No | read-only |
| `state` | string | No | read-only |
| `updated_at` | string (date-time) | 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/flows/<flow_id>/runs/" \
  -H "Authorization: Bearer $MOCHI_API_KEY" \
  -H "Idempotency-Key: $(uuidgen | tr A-Z a-z)" \
  -H "Content-Type: application/json" \
  -d '{"lead_id":1}'
```

