# Send up to 500 independent messages in one call (/api/sendMessageBatch)

Not a repeat of `POST /messages`. Each element carries its own channel,
recipient and body, and each one is answered on its own row: `index`,
the `id` that was created, and `error` when that element failed. One
mistyped number does not throw away the 499 that were fine.

The rows carry ids, not message objects. Every message is accepted as
`queued` and sent in the background, paced per number; read it back
with `GET /messages/{id}` or follow it with webhooks. Status is 200, not
201, because a batch that failed entirely still answers row by row.

Too little credit and a channel your plan does not include are reported
on the element's row (`insufficient_credits`, `channel_not_in_plan`),
not as an error for the whole call.

Endpoint: POST /api/v1/messages/batch
Full URL: https://app.sendkuy.com/api/v1/messages/batch
- header parameter Idempotency-Key (optional): string — Any unique string, one per logical request. Retrying with the same key returns the first answer instead of doing the work twice, and answers with `Idempotent…
Request body (JSON, required); required fields: messages
Example "Two channels in one call": {"messages":[{"channel":"whatsapp","to":"+6281234567890","body":"Your order is on its way."},{"channel":"email","to":"andi@example.com","subject":"Your order","body":"<p>Your order is on its way.</p>"}]}
Success status: 200

cURL:

```bash
curl -X POST https://app.sendkuy.com/api/v1/messages/batch \
  -H "Authorization: Bearer sk_live_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "messages": [
    {
      "channel": "whatsapp",
      "to": "+6281234567890",
      "body": "Your order is on its way."
    },
    {
      "channel": "email",
      "to": "andi@example.com",
      "subject": "Your order",
      "body": "<p>Your order is on its way.</p>"
    }
  ]
}'
```

Node.js:

```ts
import { SendKuy } from 'sendkuy';

const sendkuy = new SendKuy('sk_live_YOUR_API_KEY');

const result = await sendkuy.messages.sendBatch({
  messages: [
    {
      channel: 'whatsapp',
      to: '+6281234567890',
      body: 'Your order is on its way.',
    },
    {
      channel: 'email',
      to: 'andi@example.com',
      subject: 'Your order',
      body: '<p>Your order is on its way.</p>',
    },
  ],
});
```

PHP:

```php
<?php

use SendKuy\SendKuy;

$sendkuy = new SendKuy('sk_live_YOUR_API_KEY');

$result = $sendkuy->messages()->sendBatch([
    'messages' => [
        [
            'channel' => 'whatsapp',
            'to' => '+6281234567890',
            'body' => 'Your order is on its way.',
        ],
        [
            'channel' => 'email',
            'to' => 'andi@example.com',
            'subject' => 'Your order',
            'body' => '<p>Your order is on its way.</p>',
        ],
    ],
]);
```

Python:

```python
import requests

response = requests.request(
    "POST",
    "https://app.sendkuy.com/api/v1/messages/batch",
    headers={"Authorization": "Bearer sk_live_YOUR_API_KEY"},
    json={
        "messages": [
            {
                "channel": "whatsapp",
                "to": "+6281234567890",
                "body": "Your order is on its way."
            },
            {
                "channel": "email",
                "to": "andi@example.com",
                "subject": "Your order",
                "body": "<p>Your order is on its way.</p>"
            }
        ]
    },
)

data = response.json()["data"]
```