> ## Documentation Index
> Fetch the complete documentation index at: https://help.cloudtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Send and read messages with the API

> Send SMS, MMS and WhatsApp messages with the v1 Messages API, follow their delivery status, retry safely, send in bulk, and read and mark conversations.

The Messages API at `https://api.cloudtalk.io/v1` sends and reads the same SMS, MMS and WhatsApp messages your team sees in CloudTalk Phone. Use it to text a customer from your CRM, send order updates, check whether a message arrived, or show a conversation next to a customer record.

> [!NOTE]
>
> Requests authenticate with an API key, like the rest of the [CloudTalk API](https://help.cloudtalk.io/guides/authentication.md). The key acts as a company admin: it reads every conversation in your account and can send from any of your numbers.

## Send a message

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/messages \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-shipped" \
  -d '{
    "to": "+12025550143",
    "from": "+12025550100",
    "body": "Hi Jane, your order ships today."
  }'
```

```json 202 Accepted (trimmed) theme={"system"}
{
  "id": "918273",
  "conversationId": "55120",
  "direction": "outbound",
  "channel": "sms",
  "externalNumber": "+12025550143",
  "body": "Hi Jane, your order ships today.",
  "status": "queued",
  "error": null,
  "createdAt": "2026-11-12T10:00:00Z"
}
```

`202` means CloudTalk accepted the message, not that it arrived. `status` is usually `queued`, and can already be `sent`. Keep its `id` to follow it. To attach files, see [Media](#media); for up to 50 recipients in one call, see [Bulk send](#bulk-send).

## Check delivery

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  https://api.cloudtalk.io/v1/messages/918273
```

`status` follows what the mobile network reports, with the same values as the [`message.delivery_updated`](https://help.cloudtalk.io/guides/webhooks/events/messages#message-delivery_updated) webhook:

| `status` | Meaning |
| - | - |
| `queued` | Accepted, not yet with the mobile network. |
| `sent` | The network accepted it. Where the network or the sending number reports no receipt, it stays `sent`. |
| `delivered` | The network confirmed it reached the phone. |
| `not_delivered`, `failed` | It did not arrive. `error.code` says why; `error.message` can be shown to your users. |
| `seen` | WhatsApp only: the recipient read it. Best effort. |

Treat a status you do not know as still in progress. Polling counts against your [rate limit](https://help.cloudtalk.io/guides/rate-limiting.md), so prefer the webhooks: a send fires [`message.sent`](https://help.cloudtalk.io/guides/webhooks/events/messages#message-sent), each status change fires `message.delivery_updated` (its `message_id` is the message's `id`), and replies fire `message.received`.

A refused send answers an error and sends nothing. A problem the network reports later arrives as a status, not an error.

## Read conversations

A conversation is the thread between one of your numbers and one external number on one channel. Find a customer's conversations by phone number, sent in the body:

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/conversations/lookup \
  -H "Content-Type: application/json" \
  -d '{"phones": ["+12025550143"]}'
```

Then read its messages, and mark it read:

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  https://api.cloudtalk.io/v1/conversations/55120/messages

curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X PATCH https://api.cloudtalk.io/v1/conversations/55120 \
  -H "Content-Type: application/json" \
  -d '{"unread": false}'
```

Read state is shared by your whole company: marking a conversation read clears it for every user, and you cannot mark it unread again.

* **Customers waiting for you:** [List conversations](https://help.cloudtalk.io/api-reference/messages/list-conversations.md) with `awaitingReply=true`.
* **Syncing a CRM:** List conversations with `updatedAfter` set to when your previous run started, or [List messages](https://help.cloudtalk.io/api-reference/messages/list-messages.md) with `createdAfter`. Marking a conversation read does not change its `updatedAt`.
* **One contact or user:** pass `contactId` or `userId` to the lists.

Lists return `{ "data": [...], "pagination": { "limit": 20, "next": "..." }, "requestId": "..." }`, newest first. Set `limit` (default 20, at most 100) and pass `pagination.next` as `?cursor=` with the same filters until `next` is `null`. Look up conversations takes `limit` and `cursor` in the JSON body, not the query:

```json Next page of a lookup theme={"system"}
{
  "phones": ["+12025550143"],
  "limit": 20,
  "cursor": "djE6Y29udmVyc2F0aW9uLWxvb2t1cDo1NTEyMA"
}
```

## Things to know

### Choosing the number you send from

`from` takes one of your numbers, as its id or in E.164. Leave it out and the message goes from the number of your latest conversation with that recipient on that channel, so the customer keeps seeing one number. With no earlier conversation, nothing is sent and you get `422 MESSAGES.SENDER_REQUIRED`: send again with one of the numbers in `error.details.candidates` as `from`.

With `userId`, the message shows under that user's name in CloudTalk Phone. Without it, the message is marked as sent by the API and its `user` is `null`.

### Safe retries

Send an `Idempotency-Key` header (up to 50 visible ASCII characters without a colon, such as a UUID), and retry a failed request with the same key and body:

* If the message was sent, you get `202` with the message as it is now and `Idempotent-Replayed: true`, and nothing is sent again.
* If the first request is still running, you get `409 IDEMPOTENCY.IN_PROGRESS`. Retry shortly.
* If the first request was refused, the key is free again: fix the cause and send it again.
* A key names one request: a different body, or the same key on the other send endpoint, gets `422 IDEMPOTENCY.KEY_REUSED`.

Keys are kept for 7 days; after that, the same key sends again. An error with `error.details.retryable: true` may succeed later as it is: retry it with the same key.

> [!NOTE]
>
> If CloudTalk cannot tell whether a message went out, for example after a timeout on the way to the provider, it answers `202` with `status: "queued"` and `id: null`, and a retry with the same key answers the same. CloudTalk may keep no record of that message: even if it was delivered, it may not appear in the conversation, fire `message.sent` or get a status. To send it again, use a new key, knowing the recipient may get it twice.

### Bulk send

[Bulk send messages](https://help.cloudtalk.io/api-reference/messages/bulk-send-messages.md) sends one message each to 1 to 50 recipients, without media. It answers `200` with one result per row, in request order, so check each row: `status: "ok"` carries the message and `status: "error"` the refusal. An `ok` row whose message has `id: null` is the unknown outcome above: do not resend it under a new key unless you accept a duplicate. One `Idempotency-Key` covers the call, and a retry within 7 days never sends a row twice.

### Media

Upload each file first, then send its id within 24 hours:

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/message-media \
  -F "file=@receipt.jpg;type=image/jpeg"
```

```json 201 Created (trimmed) theme={"system"}
{ "id": "77120" }
```

```bash theme={"system"}
curl -u ACCESS_KEY_ID:ACCESS_KEY_SECRET \
  -X POST https://api.cloudtalk.io/v1/messages \
  -H "Content-Type: application/json" \
  -d '{"to": "+12025550143", "body": "Here is your receipt.", "mediaIds": ["77120"]}'
```

Images go by MMS (jpg, png or gif) or WhatsApp (jpg or png). Other files, such as PDF, vCard, audio and video, go by WhatsApp only. [Upload media](https://help.cloudtalk.io/api-reference/messages/upload-media.md) lists every type and size limit. Each upload goes with one message, and on SMS a message with media goes out as `mms`.

Each file on a message has `media[].url`, a signed link that downloads it with no API key. It expires 1 hour after an API read and 24 hours after a webhook is prepared. Read the message again for a fresh link, and do not log or publish links.

### WhatsApp

Send with `"channel": "whatsapp"` from one of your WhatsApp numbers. The recipient is a plain E.164 number, without a `whatsapp:` prefix.

Free-form messages are allowed only within 24 hours of the customer's last message. The conversation's `whatsappWindowEndsAt` says when the window ends. Outside it, send an approved template from [List WhatsApp templates](https://help.cloudtalk.io/api-reference/messages/list-whatsapp-templates.md) in `whatsappTemplate`, with no `body` or `mediaIds`. A free-form message outside the window gets `422 MESSAGES.WHATSAPP_WINDOW_CLOSED`. You create templates and submit them for approval in the CloudTalk Dashboard.

### API fields and webhook fields

The API uses camelCase and the message webhooks use snake\_case, with the same values for `channel`, `status` and `error.code`.

| API | Webhook | Notes |
| - | - | - |
| `id` | `id` | `message.delivery_updated` calls it `message_id`. |
| `conversationId`, `externalNumber`, `internalNumber` | `conversation_id`, `external_number`, `internal_number` | |
| `direction`, `channel`, `body`, `fragments` | the same | |
| `user.firstName`, `user.lastName` | `user.first_name`, `user.last_name` | |
| `media[]` | `media[]` | `fileName`, `contentType` and `urlExpiresAt` are `file_name`, `content_type` and `url_expires_at`. The API adds `id`. |
| `contact` | `contact` | The webhook leaves it out when there is no contact. The API sends `null`. |
| `contactAmbiguous` | `contact_ambiguous` | The webhook sends it only when it is `true`. The API always sends it. |
| `status`, `error`, `statusUpdatedAt` | `status`, `error`, `status_changed_at` | On `message.delivery_updated`. |
| `createdAt` | `created_at` | The API gives RFC 3339 to the second. |

### Errors

Errors are `{ "error": { "code", "message", "target", "details": { "retryable" } }, "requestId" }`. Branch on `code`, since `message` can change. `target` names the field at fault, such as `messages[3].to`. Quote `requestId` to support. [Error codes](https://help.cloudtalk.io/guides/error-codes.md#messages-errors) lists every code.


## Related topics

- [Send a message](https://help.cloudtalk.io/api-reference/messages/send-a-message.md)
- [Bulk send messages](https://help.cloudtalk.io/api-reference/messages/bulk-send-messages.md)
- [Mark a conversation read](https://help.cloudtalk.io/api-reference/messages/mark-a-conversation-read.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.