# Send a batch of messages

Sends up to 1,000 messages in one call. One idempotency key covers the whole batch.

`POST https://api.rassilo.ai/v1/messages/batch`

## Body parameters

`array · 1–1000`

|  |  |  |  |
| --- | --- | --- | --- |
| `channel` | `string` | required | The sending channel. — `sms` \| `whatsapp` |
| `to` | `string` | required | E.164 number, for example `+22200000000`. — `^\+[1-9]\d{6,14}$` |
| `body` | `string` | optional | The message text. May mix Arabic and French. — length 1–1600 |
| `template` | `string` | optional | A catalogue template, rendered by Rassilo instead of `body`. Send either `body` or `template`. Today: `identity_verify_otp_v1`. — `identity_verify_otp_v1` |
| `data` | `object` | optional | The template’s variables: required with `template`, not allowed without it. For `identity_verify_otp_v1`: `code` (4 to 8 digits) and `expiry_minutes` (1 to 60). |
| `language` | `string` | optional | The template variant to render: required with `template`, not allowed without it. — `ar` \| `fr` \| `en` |
| `category` | `string` | optional | The message category, which drives routing and priority. With `template`, it is the template’s own: any other value gives a `400`. — `transactional` \| `utility` \| `marketing` \| `authentication` |

## Headers

|  |  |  |  |
| --- | --- | --- | --- |
| `X-Idempotency-Key` | `string` | required | One key for the whole batch. Replaying it returns the results already obtained, without sending anything. The sample generates it with `uuidgen` (on Debian, package `uuid-runtime`). — length 0–255 |

> One invalid message rejects the whole batch, and nothing is sent. Once the batch is valid, each message has its own result: `submitted`, or `failed` with its `errorCode`.

## Example request

```sh
curl https://api.rassilo.ai/v1/messages/batch \
  -H "Authorization: Bearer $RASSILO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Idempotency-Key: $(uuidgen)" \
  -d '[
    { "channel": "sms", "to": "+22200000001", "body": "Votre colis arrive demain." },
    { "channel": "whatsapp", "to": "+22200000002", "body": "Votre colis arrive demain." }
  ]'
```

## Responses

**201** — Batch processed

```json
{
  "results": [
    {
      "channel": "sms",
      "to": "+22200000001",
      "status": "submitted",
      "provisionalId": "msg_provisoire_0002",
      "provider": "bird",
      "providerMessageId": "bird_0002",
      "errorCode": null,
      "parts": 1,
      "bodyEncoding": "GSM7"
    },
    {
      "channel": "whatsapp",
      "to": "+22200000002",
      "status": "failed",
      "provisionalId": null,
      "provider": null,
      "providerMessageId": null,
      "errorCode": "provider_send_failed"
    }
  ]
}
```

**409** — Key already used

```json
{
  "error": {
    "code": "idempotency_key_conflict"
  }
}
```

## Error codes

| HTTP | Code |  |
| --- | --- | --- |
| `400` | — | Invalid request: a parameter, a missing or too long `X-Idempotency-Key` header, or a destination this channel does not support. |
| `401` | — | Key missing or incorrect. |
| `403` | `insufficient_scope` | The key is valid but lacks the scope this operation needs, or it is a publishable key. Nothing is created. |
| `409` | — | This idempotency key was already used for another batch. |
| `413` | `payload_too_large` | The request body is too large. |
| `503` | `batch_disabled` | Service temporarily unavailable, or batch sending disabled on this server. |
