# Messages API

Source: https://aicallstudio.com/docs/api/messages. Authentication, scopes, limits, errors and webhooks: https://aicallstudio.com/docs/api

### Send an email

`POST /api/v1/messages/email` (scope `messages:send`)

Send one plain-text email to one contact, through your email connection. A real message, billed per message.

An address that bounced or complained is never sent to, nor a contact on Do-Not-Call or who withdrew consent, and nothing goes in the quiet hours. It is written on the contact's timeline. Requires an Idempotency-Key header.

This sends a real message to a real customer, billed from your wallet for each one at your plan's price per message. Send an Idempotency-Key header: without one the request is refused (428) and nothing is sent.

**Parameters**

| Parameter | Type | What it is |
| --- | --- | --- |
| `Idempotency-Key` (required) | string, up to 255 characters, in the headers | Any unique text up to 255 characters, such as a UUID, chosen by you for this request. Sent again with the same body within 24 hours, the first answer comes back (with Idempotent-Replayed: true) and nothing is done twice. The same key with another body is refused with 422. Required here: without it the request is refused with 428 and nothing is sent. |

**Request body (application/json)**

| Field | Type | What it is |
| --- | --- | --- |
| `contact_id` | string (uuid), or null | The contact to send to. Send this or the address. |
| `channel_id` | string (uuid), or null | The connection to send through (Integrations). Left out, the workspace's active connection of this kind is used; with more than one, this is required. |
| `email` | string, up to 254 characters, or null | The address to send to when you do not send contact_id. It must be a contact's address. |
| `subject` (required) | string, up to 200 characters | — |
| `body` (required) | string, up to 20000 characters | The message, as plain text. |

**Answer (200): these fields**

| Field | Type | What it is |
| --- | --- | --- |
| `channel` (required) | string | whatsapp, sms or email. |
| `status` (required) | string | sent, or queued when the channel takes it for later delivery. Delivery and reads arrive as webhooks. |
| `contact_id` (required) | string (uuid) | — |
| `message_id` | string, or null | The channel's id for the message, when it gives one. |
| `fee_inr` (required) | number | What this message cost from your wallet (0 when your plan includes it). The channel's own charge is billed by the channel. |

**Errors**

| Code | When |
| --- | --- |
| `401` | The token is missing, unknown or revoked, or its workspace was deleted. |
| `402` | The workspace's plan does not include API access. The token is paused, not revoked: it works again as soon as the plan includes API access. The wallet cannot cover this message's fee, or the plan does not include this channel. |
| `403` | The token does not have this endpoint's scope, it is a sandbox token, the workspace is suspended, or the request came from a network the workspace, or the token's IP allowlist, does not allow. |
| `404` | The contact or the connection was not found. |
| `409` | Not sent: Do-Not-Call, no consent, the customer turned off offers, the address is suppressed, quiet hours, or the connection is not active or not set up. `detail` says which. |
| `422` | A field is missing or not in the form this endpoint takes. `detail` says which, and why. |
| `428` | No Idempotency-Key header. Nothing was sent. |
| `429` | This token has made more requests this minute than your plan allows. The Retry-After header says how many seconds to wait. |
| `502` | The channel did not take the message. Nothing was charged. |

```bash
curl -X POST "https://aicallstudio.com/api/v1/messages/email" \
  -H "Authorization: Bearer mtc_YOUR_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"contact_id":"YOUR_CONTACT_ID","subject":"Your receipt","body":"Thank you, we received your payment."}'
```

### Send an SMS

`POST /api/v1/messages/sms` (scope `messages:send`)

Send the SMS connection's registered template to one person. A real message, billed per message.

Only the registered template goes (India's DLT rules), never free text. Do-Not-Call, consent and the quiet hours apply. It is written on the contact's timeline. Requires an Idempotency-Key header.

This sends a real message to a real customer, billed from your wallet for each one at your plan's price per message. Send an Idempotency-Key header: without one the request is refused (428) and nothing is sent.

**Parameters**

| Parameter | Type | What it is |
| --- | --- | --- |
| `Idempotency-Key` (required) | string, up to 255 characters, in the headers | Any unique text up to 255 characters, such as a UUID, chosen by you for this request. Sent again with the same body within 24 hours, the first answer comes back (with Idempotent-Replayed: true) and nothing is done twice. The same key with another body is refused with 422. Required here: without it the request is refused with 428 and nothing is sent. |

**Request body (application/json)**

| Field | Type | What it is |
| --- | --- | --- |
| `contact_id` | string (uuid), or null | The contact to send to. Send this or the address. |
| `channel_id` | string (uuid), or null | The connection to send through (Integrations). Left out, the workspace's active connection of this kind is used; with more than one, this is required. |
| `phone` | string, up to 20 characters, or null | The number to send to when you do not send contact_id. A new number is saved as a contact. |
| `name` | string, up to 255 characters, or null | The person's name, for a new number. |
| `template` (required) | string, up to 200 characters | The SMS connection's registered template, by its name or id. Only that template is sent, never free text (India's DLT rules). |
| `values` | object | The template's variables by name. |

**Answer (200): these fields**

| Field | Type | What it is |
| --- | --- | --- |
| `channel` (required) | string | whatsapp, sms or email. |
| `status` (required) | string | sent, or queued when the channel takes it for later delivery. Delivery and reads arrive as webhooks. |
| `contact_id` (required) | string (uuid) | — |
| `message_id` | string, or null | The channel's id for the message, when it gives one. |
| `fee_inr` (required) | number | What this message cost from your wallet (0 when your plan includes it). The channel's own charge is billed by the channel. |

**Errors**

| Code | When |
| --- | --- |
| `401` | The token is missing, unknown or revoked, or its workspace was deleted. |
| `402` | The workspace's plan does not include API access. The token is paused, not revoked: it works again as soon as the plan includes API access. The wallet cannot cover this message's fee, or the plan does not include this channel. |
| `403` | The token does not have this endpoint's scope, it is a sandbox token, the workspace is suspended, or the request came from a network the workspace, or the token's IP allowlist, does not allow. |
| `404` | The contact or the connection was not found. |
| `409` | Not sent: Do-Not-Call, no consent, the customer turned off offers, the address is suppressed, quiet hours, or the connection is not active or not set up. `detail` says which. |
| `422` | A field is missing or not in the form this endpoint takes. `detail` says which, and why. |
| `428` | No Idempotency-Key header. Nothing was sent. |
| `429` | This token has made more requests this minute than your plan allows. The Retry-After header says how many seconds to wait. |
| `502` | The channel did not take the message. Nothing was charged. |

```bash
curl -X POST "https://aicallstudio.com/api/v1/messages/sms" \
  -H "Authorization: Bearer mtc_YOUR_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"phone":"9876543210","name":"Asha Verma","template":"YOUR_TEMPLATE_NAME","values":{"amount":"12,500"}}'
```

### Send a WhatsApp template

`POST /api/v1/messages/whatsapp` (scope `messages:send`)

Send one approved WhatsApp template to one person. A real message, billed per message.

The same checks as the inbox: the template must be approved for the connection, a customer on Do-Not-Call or without consent is never messaged, one who turned off offers is not sent a marketing template, and nothing goes in the quiet hours. The message lands in the WhatsApp inbox and the contact's timeline (the inbox.message_sent webhook); delivered and read follow as the channel reports them. Requires an Idempotency-Key header.

This sends a real message to a real customer, billed from your wallet for each one at your plan's price per message. Send an Idempotency-Key header: without one the request is refused (428) and nothing is sent.

**Parameters**

| Parameter | Type | What it is |
| --- | --- | --- |
| `Idempotency-Key` (required) | string, up to 255 characters, in the headers | Any unique text up to 255 characters, such as a UUID, chosen by you for this request. Sent again with the same body within 24 hours, the first answer comes back (with Idempotent-Replayed: true) and nothing is done twice. The same key with another body is refused with 422. Required here: without it the request is refused with 428 and nothing is sent. |

**Request body (application/json)**

| Field | Type | What it is |
| --- | --- | --- |
| `contact_id` | string (uuid), or null | The contact to send to. Send this or the address. |
| `channel_id` | string (uuid), or null | The connection to send through (Integrations). Left out, the workspace's active connection of this kind is used; with more than one, this is required. |
| `phone` | string, up to 20 characters, or null | The number to send to when you do not send contact_id: 8 to 15 digits, optionally starting with +. A new number is saved as a contact (send `name` for it). |
| `name` | string, up to 255 characters, or null | The person's name, for a new number. |
| `template` (required) | string, up to 200 characters | The name of a WhatsApp template approved for this connection. Only approved templates are sent; free text is not, because the 24-hour window may be closed. |
| `values` | object | The template's blanks by their number or name, such as {"1": "Asha", "2": "12,500"}. A blank left out is filled from the contact where it can be. |

**Answer (200): these fields**

| Field | Type | What it is |
| --- | --- | --- |
| `channel` (required) | string | whatsapp, sms or email. |
| `status` (required) | string | sent, or queued when the channel takes it for later delivery. Delivery and reads arrive as webhooks. |
| `contact_id` (required) | string (uuid) | — |
| `message_id` | string, or null | The channel's id for the message, when it gives one. |
| `fee_inr` (required) | number | What this message cost from your wallet (0 when your plan includes it). The channel's own charge is billed by the channel. |

**Errors**

| Code | When |
| --- | --- |
| `401` | The token is missing, unknown or revoked, or its workspace was deleted. |
| `402` | The workspace's plan does not include API access. The token is paused, not revoked: it works again as soon as the plan includes API access. The wallet cannot cover this message's fee, or the plan does not include this channel. |
| `403` | The token does not have this endpoint's scope, it is a sandbox token, the workspace is suspended, or the request came from a network the workspace, or the token's IP allowlist, does not allow. |
| `404` | The contact or the connection was not found. |
| `409` | Not sent: Do-Not-Call, no consent, the customer turned off offers, the address is suppressed, quiet hours, or the connection is not active or not set up. `detail` says which. |
| `422` | A field is missing or not in the form this endpoint takes. `detail` says which, and why. |
| `428` | No Idempotency-Key header. Nothing was sent. |
| `429` | This token has made more requests this minute than your plan allows. The Retry-After header says how many seconds to wait. |
| `502` | The channel did not take the message. Nothing was charged. |

```bash
curl -X POST "https://aicallstudio.com/api/v1/messages/whatsapp" \
  -H "Authorization: Bearer mtc_YOUR_TOKEN" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"contact_id":"YOUR_CONTACT_ID","template":"emi_reminder","values":{"1":"Asha","2":"12,500"}}'
```
