Messages API
SMS and WhatsApp messages sent through the API.
The same operations are in the interactive API reference, and the whole contract is in the OpenAPI document.
GET/v1/messages
List messages
Returns the SMS and WhatsApp messages sent through this API, newest first, both channels in one list.
Needs messages:read. Reading is free. A test key lists the sandbox's simulated messages only.
Filter with channel (sms or whatsapp, anything else is a 400) and status. status is matched exactly against the message's status and an unknown value just returns an empty list.
Paged, newest first: limit is 1 to 100 (default 50, out of range values are clamped) and cursor is the next_cursor of the previous page. The cursor is opaque and never built by the client; a cursor this API did not return is a 400. has_more is true while another page exists. There is no total.
SMS rows have body: null, because the text of an SMS is not kept.
Scope messages:read. Accepts: API key or personal access token. Open in the API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
channel | query | string | No | Only this channel. |
status | query | string | No | Only this status, such as `delivered` or `failed`. |
limit | query | integer | No | How many items to return. Default 50, at most 100. |
cursor | query | string | No | The `next_cursor` of the previous page. Opaque; never built by the client. |
AirFone-Version | header | string | No | The API version to use, as a date. Defaults to the version the account was pinned to. |
POST/v1/messages
Send a message
Sends one SMS or one WhatsApp message and returns it as stored, so the id can be used to read the delivery state later.
Needs messages:write.
SMS. to must be a Nepal mobile number and body is required, 1 to 1600 characters. Long text is billed per part (segments). The organization needs a verified phone and the message is screened. A template is refused here. A test key cannot send SMS: it is refused with 403, because simulating SMS would suggest a number was reached. Use a live key from a business organization.
WhatsApp. to is a number with country code, 8 to 15 digits, with or without the plus. Send either body (free text, up to 4096 characters) or template, never both and never neither. Free text is allowed only within 24 hours of that person's last message to you; outside it the request is refused with 409 and you must send an approved template. A template works at any time. WhatsApp must be connected for the organization or the answer is 409. A test key simulates WhatsApp: nobody is messaged, nothing is charged, and the message has test: true.
Cost. A live SMS is paid from credit per part. Without enough credit the request is refused with 402 insufficient_credit and nothing is sent. WhatsApp messages are not charged here.
Status. The answer is 201 with status: sent when the provider accepted the message within the request, and 202 with status: queued when it has not answered yet. A WhatsApp message then moves to delivered or read as WhatsApp reports. SMS stays sent once the carrier accepts it.
Idempotency. Send an Idempotency-Key. Without one, retrying after a timeout can message the person twice. With one, a repeat returns the first result. The same key with a different body is a 409.
The text of an SMS is not kept. The response echoes what you sent, but reading the message later returns body: null.
Scope messages:write. Accepts: API key or personal access token. Open in the API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
Idempotency-Key | header | string | No | Makes a POST safe to repeat: the same key returns the first result for 24 hours. The same key with a different body is refused with `422 idempotency_key_reused`; while the first request still runs, `409 idempotency_in_progress`. |
AirFone-Version | header | string | No | The API version to use, as a date. Defaults to the version the account was pinned to. |
GET/v1/messages/{id}
Get a message
Returns one message sent through this API, with its current delivery status. Use it to follow a WhatsApp message from queued to delivered or read, or to find out why a send failed (status_detail).
Needs messages:read. Reading is free. A message from another organization, from the other mode, or one that was not sent through the API answers 404.
For SMS, body is null: the text is not kept. For a WhatsApp template the body reads Template: <name>.
Scope messages:read. Accepts: API key or personal access token. Open in the API reference
| Parameter | In | Type | Required | Description |
|---|---|---|---|---|
id | path | string | Yes | The resource id. |
AirFone-Version | header | string | No | The API version to use, as a date. Defaults to the version the account was pinned to. |