## Create campaign

`POST https://whatsapp.paaltech.org/api/v1/businesses/{external_id}/campaigns`

A draft broadcast of one APPROVED template to a segment or a list of contacts.
`parameters` maps each template variable to a source per contact - `field:name`
(name, phone, email, external_id), `custom:<key>` or `text:<fixed text>`. Preview it,
then launch it - now, at `send_at`, or repeating every `week` or `month`.

Ability: `campaigns.manage`

### Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `external_id` | string | yes | Your own ID for the business (Multi-SKUUL - the tenant ID). Max 191 characters. Pattern `^[A-Za-z0-9._:-]+$` |

### Body

| Name | Type | Required | Description |
|---|---|---|---|
| `name` | string | yes | Max 191 characters |
| `template` | object | yes |  |
| `template.name` | string | yes |  |
| `template.language` | string | yes |  |
| `parameters` | object | no |  |
| `segment_id` | integer | null | no | The audience - or contact_ids. |
| `contact_ids` | array of integers | null | no | Max 10000 items |
| `phone_number_id` | string | null | no |  |
| `category` | string | null | no | One of: `marketing`, `notifications`, `transactional`, `` |
| `topic` | string | null | no | One of: `fees`, `results`, `attendance`, `pta`, `marketing`, `system`, `` |
| `send_at` | string | null | no | Format date-time |
| `repeat` | string | null | no | One of: `week`, `month`, `` |
| `per_minute` | integer | null | no | Pace: messages per minute (default 60). |

### Request

```bash
curl --request POST \
  --url 'https://whatsapp.paaltech.org/api/v1/businesses/presec/campaigns' \
  --header "Authorization: Bearer $PAALCHAT_TOKEN" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "October fee reminders",
  "template": {"name": "school_fee_reminder", "language": "en_US"},
  "parameters": {
    "parent": "field:name",
    "amount": "custom:fee_balance",
    "student": "custom:ward_name",
    "due_date": "text:30 October"
  },
  "segment_id": 4,
  "topic": "fees"
}'
```

### Responses

- **201** - The draft.
- **401** - unauthenticated - missing, invalid, revoked or expired token

```json
{
  "error": {"code": "unauthenticated", "message": "A valid product token is required."}
}
```

- **403** - missing_ability, product_suspended or product_token_required

```json
{
  "error": {
    "code": "missing_ability",
    "message": "This token does not have the ability this request needs."
  }
}
```

- **404** - not_found - not yours, or does not exist

```json
{"error": {"code": "not_found", "message": "Business not found."}}
```

- **422** - validation_failed or unknown_template.
- **429** - rate_limited - over 300 requests/minute for this product

```json
{
  "error": {
    "code": "rate_limited",
    "message": "Too many requests. Slow down and retry after the Retry-After header."
  }
}
```

