# Keyword automations

Create a keyword-triggered automation draft.

Create a keyword-triggered automation draft.

## Create keyword automation

`POST /v1/automations/keyword/`

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 |
| --- | --- | --- | --- |
| `active_hours` | object \| null | No |  |
| `active_hours.windows` | object[] | Yes | max 14 items |
| `active_hours.windows[].day` | string | Yes | one of `MONDAY`, `TUESDAY`, `WEDNESDAY`, `THURSDAY`, `FRIDAY`, `SATURDAY`, `SUNDAY` |
| `active_hours.windows[].end` | string | Yes | max length 5 |
| `active_hours.windows[].start` | string | Yes | max length 5 |
| `assigned_member_id` | integer \| null | No |  |
| `comment_type` | string | No | one of `ANY_POST`, `SPECIFIC_POST` |
| `future_post_slots` | integer | No |  |
| `is_active` | boolean | Yes |  |
| `keywords` | string[] | No | max 20 items |
| `match_mode` | string | No | one of `contains`, `is_exactly` |
| `media_ids` | string[] | No | max 50 items |
| `name` | string | Yes | max length 255 |
| `once_per_lead` | boolean | No |  |
| `override_existing_assignment` | boolean | No |  |
| `replies` | object[] | Yes | max 20 items |
| `replies[].ai_prompt` | string | No | max length 2000 |
| `replies[].ask_email_timeout_seconds` | integer | No |  |
| `replies[].delay` | integer | No |  |
| `replies[].file_id` | string (uuid) \| null | No |  |
| `replies[].media_kind` | string | No | one of `IMAGE`, `VIDEO`, `AUDIO` |
| `replies[].reply_type` | string | No | one of `DM`, `COMMENT`, `ASK_EMAIL`, `MEDIA` |
| `replies[].text` | string | No | max length 1000 |
| `replies[].variant_pairing` | string | No | one of `INDEPENDENT`, `FOLLOW_PREVIOUS` |
| `replies[].variants` | object[] | No | max 10 items |
| `replies[].variants[].buttons` | object[] | No | max 3 items |
| `replies[].variants[].buttons[].button_type` | string | No | one of `URL`, `POSTBACK` |
| `replies[].variants[].buttons[].name` | string | Yes | max length 20 |
| `replies[].variants[].buttons[].payload` | string \| null | No | max length 1000 |
| `replies[].variants[].buttons[].url` | string \| null | No | max length 2000 |
| `replies[].variants[].file_id` | string (uuid) \| null | No |  |
| `replies[].variants[].media_kind` | string | No | one of `IMAGE`, `VIDEO`, `AUDIO` |
| `replies[].variants[].text` | string | No | max length 1000 |
| `replies[].variants[].traffic_percentage` | integer | No |  |
| `set_stage` | string \| null | No | one of `NEW`, `IN_CONTACT`, `QUALIFIED`, `UNQUALIFIED`, `BOOKED_CALL`, `DEPOSIT`, `WON`, `LOST`, `NO_SHOW` |
| `tags` | string[] | No | max 50 items |
| `tags_to_remove` | string[] | No | max 50 items |
| `triggers` | object[] | No | max 10 items |
| `triggers[].comment_type` | string \| null | No | one of `ANY_POST`, `SPECIFIC_POST` |
| `triggers[].future_post_slots` | integer | No |  |
| `triggers[].keywords` | string[] | Yes | max 20 items |
| `triggers[].lead_filter` | object \| null | No |  |
| `triggers[].match_mode` | string | No | one of `contains`, `is_exactly` |
| `triggers[].media_ids` | string[] | No |  |
| `triggers[].trigger_type` | string | Yes | one of `DM`, `COMMENT`, `STORY` |

### Response (201)

| Field | Type | Required | Notes |
| --- | --- | --- | --- |
| `active_hours` | object | No | read-only |
| `active_hours.windows` | object[] | No | read-only |
| `active_hours.windows[].day` | string | No | read-only |
| `active_hours.windows[].end` | string | No | read-only |
| `active_hours.windows[].start` | string | No | read-only |
| `comment_type` | 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 |
| `once_per_lead` | boolean | No | read-only |
| `reply_count` | integer | No | read-only |
| `set_stage` | string \| null | No | read-only |
| `trigger_count` | integer | No | read-only |
| `trigger_type` | string | 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/keyword/" \
  -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","replies":[{"ai_prompt":"string","ask_email_timeout_seconds":1,"delay":1,"file_id":"00000000-0000-4000-8000-000000000000","media_kind":"IMAGE","reply_type":"DM","text":"string","variant_pairing":"INDEPENDENT","variants":[{}]}]}'
```

