# API reference

> REST API for Zyptos: authentication, errors, rate limits and every v1 endpoint.

Source: https://zyptos.com/docs/api

## Overview

The Zyptos API is a JSON REST API for your workspace: send WhatsApp messages, manage contacts, read templates and conversations, and start broadcasts. The machine-readable spec is at [/api/v1/openapi.json](https://zyptos.com/api/v1/openapi.json) (OpenAPI 3.1). To use the same operations from an AI assistant, connect the [MCP server](https://zyptos.com/docs/mcp).

Base URL:

```text
https://zyptos.com/api/v1
```

## Authentication

Create a key in the app under `Settings` > `New API key` (owners and admins). Keys look like `zk_live_…`, are shown once and stored only as a hash. Send the key as a Bearer token. Revoking a key in Settings stops it immediately.

curl:

```bash
curl https://zyptos.com/api/v1/me \
  -H "Authorization: Bearer $ZYPTOS_API_KEY"
```

Each key has scopes. A request outside the key's scopes gets 403.

| Scope | Allows |
| --- | --- |
| `contacts:read` | Read contacts |
| `contacts:write` | Create and update contacts |
| `messages:read` | Read conversations and messages |
| `messages:send` | Send messages |
| `templates:read` | Read templates |
| `broadcasts:write` | Create and read broadcasts |

## Send your first message

Templates can be sent any time (except to opted-out contacts). Free text needs the contact's 24-hour window to be open.

Send a template:

```bash
curl -X POST https://zyptos.com/api/v1/messages \
  -H "Authorization: Bearer $ZYPTOS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "template",
    "to": "+91 98765 43210",
    "template": { "name": "order_update", "language": "en", "variables": ["Asha", "#1042"] }
  }'
```

The response is `202 Accepted` with the message in status `queued`. It moves to `sent`, `delivered` and `read` as Meta reports; follow it with [GET /messages/{id}](https://zyptos.com/docs/api#getMessage) or the [message.status webhook](https://zyptos.com/docs/webhooks).

## Errors

Errors use HTTP status codes and one JSON shape. Branch on `code`; `message` is for humans.

400 Bad Request:

```json
{
  "error": {
    "code": "validation_error",
    "message": "The request has invalid or missing fields.",
    "details": [{ "path": "phone", "message": "Invalid input: expected string, received undefined" }]
  }
}
```

| Status | code | When |
| --- | --- | --- |
| 400 | `validation_error` | Invalid JSON, missing or invalid fields, wrong number of template variables |
| 401 | `unauthorized` | Missing, malformed, unknown or revoked key |
| 403 | `forbidden` | The key lacks the required scope |
| 403 | `workspace_inactive` | The workspace is suspended or cancelled |
| 404 | `not_found` | No such resource in this workspace, or no such endpoint |
| 409 | `opted_out` | Template to a contact who opted out |
| 422 | `no_whatsapp_number` | No connected WhatsApp number |
| 422 | `window_closed` | Free text outside the 24-hour window |
| 422 | `template_not_approved` | Unknown, unapproved or authentication template |
| 429 | `rate_limited` | Too many requests (see Retry-After) |
| 503 | `sending_paused` | Sending is paused platform-wide, or the queue is unavailable (service_unavailable) |

## Rate limits

Each key can make 120 requests per minute. Every response carries `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset` (Unix seconds). Over the limit you get 429 with `Retry-After`. Message delivery itself is paced by WhatsApp and your number's messaging limit; for large sends, use [broadcasts](https://zyptos.com/docs/api#createBroadcast).

## Pagination

List endpoints take `page` (from 1) and `limit` (1–100, default 50) and return `data`, `page`, `limit`, `total` and `has_more`. Timestamps are ISO 8601 in UTC; phone numbers are digits with country code and no plus sign.

> **Testing** There is no sandbox yet. Use a test number you own, or contacts who expect your messages.

## Endpoints

### Get the current workspace

`GET https://zyptos.com/api/v1/me` · any key

Returns the workspace the key belongs to, the key's scopes and the connected WhatsApp numbers. Works with any valid key.

Response 200: OK.

### Get this month's usage

`GET https://zyptos.com/api/v1/usage` · any key

Message counts for the current calendar month (UTC): sent and received, failed, conversations with activity, billable messages by Meta pricing category, broadcasts created, plus the total number of contacts. Works with any valid key. Meta bills conversation charges directly; these are counts, not amounts.

Response 200: OK.

### Send a message

`POST https://zyptos.com/api/v1/messages` · scope `messages:send`

Queues a text or template message from the workspace's connected number and returns it with status `queued` (202). Text messages are only allowed while the customer service window is open (24 hours after the contact's last message); outside it, send an approved template. Templates are never sent to opted-out contacts.

Request body (JSON):

- `type` ("text", required)
- `to` (string): Recipient phone number. Creates the contact if it's new.
- `contact_id` (string): Recipient contact id (instead of `to`)
- `text` (object, required)
- `text.body` (string, required)
- `text.preview_url` (boolean): Show a link preview for the first URL

Or:

- `type` ("template", required)
- `to` (string): Recipient phone number. Creates the contact if it's new.
- `contact_id` (string): Recipient contact id (instead of `to`)
- `template` (object, required)
- `template.name` (string, required): Template name as approved by Meta
- `template.language` (string, required): Template language code, e.g. en or en_US
- `template.variables` (string[]): Values for {{1}}, {{2}}… in order
- `template.header_media_url` (string): Public https link for an IMAGE, VIDEO or DOCUMENT header

Response 202: Message object.

### Get a message

`GET https://zyptos.com/api/v1/messages/{id}` · scope `messages:read`

Poll this, or subscribe to the message.status webhook, to follow a message from queued to sent, delivered and read.

Parameters:

- `id` (path, string, required): Resource id

Response 200: Message object.

### List contacts

`GET https://zyptos.com/api/v1/contacts` · scope `contacts:read`

Newest first. Filter by search text, tag or opt-out state.

Parameters:

- `page` (query, integer): Page number, from 1
- `limit` (query, integer): Items per page (1–100)
- `q` (query, string): Matches name, profile name, phone or email
- `tag` (query, string): Only contacts with this tag
- `opted_out` (query, "true" | "false"): Filter by opt-out state

Response 200: paginated list of Contact (`data`, `page`, `limit`, `total`, `has_more`).

### Create or update a contact

`POST https://zyptos.com/api/v1/contacts` · scope `contacts:write`

Upserts by phone number: if the number already exists in the workspace, the given fields are merged into it (tags are added, not replaced) and 200 is returned instead of 201.

Request body (JSON):

- `phone` (string, required): Phone number with country code, e.g. +91 98765 43210 or 919876543210
- `name` (string)
- `email` (string)
- `tags` (string[])
- `attributes` (object): Custom key/value fields
- `opted_out` (boolean)

Response 201: Contact object.

### Get a contact

`GET https://zyptos.com/api/v1/contacts/{id}` · scope `contacts:read`

Parameters:

- `id` (path, string, required): Resource id

Response 200: Contact object.

### Update a contact

`PATCH https://zyptos.com/api/v1/contacts/{id}` · scope `contacts:write`

Only the fields you send change. `tags` and `attributes` replace the stored values; send null for name or email to clear them.

Parameters:

- `id` (path, string, required): Resource id

Request body (JSON):

- `name` (string | null)
- `email` (string | null)
- `tags` (string[])
- `attributes` (object): Custom key/value fields
- `opted_out` (boolean)

Response 200: Contact object.

### List message templates

`GET https://zyptos.com/api/v1/templates` · scope `templates:read`

Templates synced from Meta for this workspace's numbers (refreshed every 6 hours, on status webhooks, and when you press Sync in the app).

Parameters:

- `page` (query, integer): Page number, from 1
- `limit` (query, integer): Items per page (1–100)
- `status` (query, "APPROVED" | "PENDING" | "REJECTED" | "PAUSED" | "DISABLED")
- `language` (query, string)

Response 200: paginated list of Template (`data`, `page`, `limit`, `total`, `has_more`).

### List conversations

`GET https://zyptos.com/api/v1/conversations` · scope `messages:read`

One conversation per contact and number, most recent activity first.

Parameters:

- `page` (query, integer): Page number, from 1
- `limit` (query, integer): Items per page (1–100)
- `status` (query, "open" | "closed")

Response 200: paginated list of Conversation (`data`, `page`, `limit`, `total`, `has_more`).

### List messages in a conversation

`GET https://zyptos.com/api/v1/conversations/{id}/messages` · scope `messages:read`

Newest first.

Parameters:

- `id` (path, string, required): Resource id
- `page` (query, integer): Page number, from 1
- `limit` (query, integer): Items per page (1–100)

Response 200: paginated list of Message (`data`, `page`, `limit`, `total`, `has_more`).

### Create a broadcast

`POST https://zyptos.com/api/v1/broadcasts` · scope `broadcasts:write`

Sends an approved template to many contacts. Opted-out contacts are skipped when the audience is resolved. Sends go through the platform's rate-limited broadcast queue (20 messages per second by default), and Meta's own per-number messaging limit still applies. Variables may use {{name}} and {{phone}}, filled per contact.

Request body (JSON):

- `name` (string)
- `template` (object, required)
- `template.name` (string, required): Template name as approved by Meta
- `template.language` (string, required): Template language code, e.g. en or en_US
- `template.variables` (string[]): Values for {{1}}, {{2}}… in order
- `template.header_media_url` (string): Public https link for an IMAGE, VIDEO or DOCUMENT header
- `audience` (object | object | object, required): Exactly one of: { all: true }, { tag }, or { contact_ids }

Response 202: Broadcast object.

### Get a broadcast

`GET https://zyptos.com/api/v1/broadcasts/{id}` · scope `broadcasts:write`

Includes per-status recipient counts.

Parameters:

- `id` (path, string, required): Resource id

Response 200: Broadcast object.

## Objects

### Message

- `id` (string, required)
- `conversation_id` (string | null, required)
- `contact_id` (string | null, required)
- `direction` ("in" | "out", required)
- `type` (string, required): text, template, image, video, audio, document, sticker, location, interactive, button, reaction…
- `text` (string | null, required): Text body or media caption
- `template` (object | null, required)
- `media` (object | null, required)
- `status` ("queued" | "sent" | "delivered" | "read" | "failed" | "received" | string, required)
- `error` (string | null, required)
- `wa_message_id` (string | null, required): Meta's message id (wamid), once sent
- `broadcast_id` (string | null, required)
- `sent_at` (string | null, required)
- `delivered_at` (string | null, required)
- `read_at` (string | null, required)
- `created_at` (string, required): ISO 8601 timestamp (UTC)

### Contact

- `id` (string, required)
- `phone` (string, required): WhatsApp ID: international number without '+', e.g. 919876543210
- `name` (string | null, required)
- `profile_name` (string | null, required): Name from the customer's WhatsApp profile
- `email` (string | null, required)
- `tags` (string[], required)
- `attributes` (object, required)
- `opted_out` (boolean, required): True after the contact replied STOP, or when set by you. Opted-out contacts never receive templates or broadcasts.
- `source` (string, required): whatsapp, manual, csv or api
- `last_inbound_at` (string | null, required)
- `created_at` (string, required): ISO 8601 timestamp (UTC)

### Template

- `id` (string, required)
- `name` (string, required)
- `language` (string, required)
- `category` (string | null, required): MARKETING, UTILITY or AUTHENTICATION
- `status` (string, required): APPROVED, PENDING, REJECTED, PAUSED or DISABLED
- `body` (string, required): Body text with {{1}}, {{2}} placeholders
- `variables` (integer, required): Number of body placeholders to fill when sending
- `header_format` (string | null, required): TEXT, IMAGE, VIDEO or DOCUMENT when the template has a header
- `rejected_reason` (string | null, required)
- `updated_at` (string, required): ISO 8601 timestamp (UTC)

### Conversation

- `id` (string, required)
- `status` ("open" | "closed" | string, required)
- `unread` (integer, required)
- `preview` (string | null, required)
- `last_message_at` (string | null, required)
- `last_inbound_at` (string | null, required)
- `window_open` (boolean, required): True while free-form replies are allowed (24 hours after the customer's last message)
- `contact` (object, required)
- `contact.id` (string, required)
- `contact.phone` (string, required)
- `contact.name` (string | null, required)

### Broadcast

- `id` (string, required)
- `name` (string, required)
- `template` (object, required)
- `template.name` (string, required)
- `template.language` (string, required)
- `status` (string, required): queued, sending, completed or cancelled
- `total` (integer, required)
- `stats` (object, required)
- `stats.pending` (integer, required)
- `stats.sent` (integer, required)
- `stats.delivered` (integer, required)
- `stats.read` (integer, required)
- `stats.failed` (integer, required)
- `stats.skipped` (integer, required)
- `created_at` (string, required): ISO 8601 timestamp (UTC)
- `started_at` (string | null, required)
- `completed_at` (string | null, required)

### Error

- `error` (object, required)
- `error.code` (string, required): Stable machine-readable code
- `error.message` (string, required): Human-readable explanation
- `error.details` (object[]): Per-field problems for validation_error
