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

# API reference

> The two hosts, the two kinds of key, the headers, the limits and the answers of the Maqetin API.

| Host | Routes | Key |
| - | - | - |
| `https://in.maqetin.com` | [`POST /v1/identify`](https://docs.maqetin.com/api-reference/identify), [`POST /v1/track`](https://docs.maqetin.com/api-reference/track), [`POST /v1/batch`](https://docs.maqetin.com/api-reference/batch) | Public key. `/v1/batch` also takes a secret key. |
| `https://api.maqetin.com` | [`POST /v1/public/messages`](https://docs.maqetin.com/api-reference/send-message), [`/v1/public/contacts`](https://docs.maqetin.com/api-reference/contacts) | Secret key |

Events go in on one host and messages go out from the other. Each route takes an API key in the `Authorization` header and acts in the key's own workspace. The JavaScript SDK makes the event calls for you; call the routes yourself from a language that has no SDK.

## Keys

A **public key** (`mq_live_`) can only write events, so it is safe in a web page or an app. A **secret key** (`mq_sec_`) stays on your server and does what its scopes allow; you choose them when you [make the key](https://docs.maqetin.com/workspace/api-keys.md). A secret key made with no scopes has `contacts:read` only.

```http theme={null}
Authorization: Bearer mq_live_…
```

> [!WARNING]
>
> Never put a secret key in a web page, an app or a repository. Anyone who holds it can read your contacts, delete them or send email from your workspace, as far as its scopes allow.

### Which key each route takes

| Route | Public key | Secret key, by scope |
| - | - | - |
| `POST /v1/identify`, `POST /v1/track` | Yes | No: `401` |
| `POST /v1/batch` | Yes | With `events:write`, to send events. Without it: `401` |
| `POST /v1/public/messages` | No: `401` | With `messages:send`, to send a transactional message. Without it: `403` |
| `GET /v1/public/contacts…` | No: `401` | With `contacts:read`, to list, read and export contacts, and read their messages. Without it: `403` |
| `DELETE /v1/public/contacts/{contactId}` | No: `401` | With `contacts:delete`, to delete a contact. Without it: `403` |

Events sent with a secret key are marked as sent by your server. Once such a call sets `email`, `phone` or `emailOptIn`, a public-key call can no longer change that value, but it can still fill one that is empty.

## Identity token

A call to `/v1/identify`, `/v1/track` or `/v1/batch` that names a `userId` can carry a token your server signed for that person. Set it up in [Identity verification](https://docs.maqetin.com/data/identity-verification.md).

```http theme={null}
Maqetin-Identity-Token: eyJhbGciOiJFUzI1NiIs…
```

The token is a JWT signed with ES256 by a key of your workspace, named in its header's `kid`. Its `sub` is the `userId` and its `exp` is at most 24 hours ahead. One token covers one request, so every item of a batch that names a `userId` must name the token's `sub`. A call that names only an `anonymousId` needs no token, and neither does a secret key on `/v1/batch`.

| Mode | A call with a valid token | A call with no token, or a token that fails |
| - | - | - |
| `required`, also when no mode is chosen | Accepted | Refused with `401` and the reason |
| `optional` | Accepted | Accepted |
| `disabled` | Accepted, the token is not read | Accepted |

The reasons of a `401` are `token_required`, `token_expired`, `invalid_signature`, `sub_mismatch`, `no_matching_key` and `exp_required`; see [Errors](https://docs.maqetin.com/api-reference/errors.md#identity-token).

## Send an event once

Give each event a `messageId` of 1 to 64 characters. A retry with the same `messageId` within 24 hours is stored once. A call without one gets an id from the gateway, and a retry of it is stored again.

## Send a message once

`POST /v1/public/messages` takes an optional `Idempotency-Key` header: letters, digits and `_ . : -`, at most 100 characters. A retry with the same key within 7 days sends the message once and answers with the same `messageId`. The first body sent with a key is the one that counts.

```http theme={null}
Idempotency-Key: order-42:receipt
```

## Event time

An event is stored with the time the gateway received it, unless you send both `timestamp` (when the event happened) and `sentAt` (when the request left your client). With both, and `timestamp` earlier than `sentAt`, Maqetin stores the time of receipt minus the gap between them, so a wrong client clock cancels out. A `timestamp` alone is not used. A `timestamp` more than 366 days before `sentAt` is a `400`. Send times as ISO 8601 date-times, such as `2026-12-03T09:30:00.000Z`.

## Rate limits

| Host | Limit, per key |
| - | - |
| `in.maqetin.com` | 1,000 events a second. A batch counts each item. |
| `in.maqetin.com` | 100 refused requests a second (`400`, `413`, `415`) |
| `api.maqetin.com` | 600 requests a minute, across messages and contacts |
| `api.maqetin.com` | 300 sends a minute on `POST /v1/public/messages`. Each send also counts in the 600. |

Over a limit, the answer is `429` with a `Retry-After` header in seconds: wait that long, then retry with the same `messageId` or `Idempotency-Key`.

## Size limits

| What | Limit |
| - | - |
| Body of `/v1/identify` or `/v1/track` | 32 KiB |
| Body of `/v1/batch` | 512 KiB, and 1 to 100 items |
| One event as stored | 900,000 bytes. Over it, the request is a `413`. |
| Nesting of one event | 32 levels |
| Body of a request to `api.maqetin.com` | 100 KiB |
| `data` of a message | 16 KiB (16,384 bytes) as JSON |
| Compression | `in.maqetin.com` refuses a compressed body with `415`. Send plain JSON. |

## Answers

> [tab] in.maqetin.com
>
> An accepted call is `202` with the number of events taken:
>
> ```json theme={null}
> { "accepted": 1 }
> ```
>
> A refusal holds `error`, and for a body problem `at`: up to 10 places in the body, as JSON pointers. A name you chose is shown as `*`. No value from the body is repeated.
>
> ```json theme={null}
> { "error": "invalid payload", "at": ["/traits/email"] }
> ```

> [tab] api.maqetin.com
>
> Every answer holds `success` and `meta`. A success holds `data`:
>
> ```json theme={null}
> {
>   "success": true,
>   "data": { "messageId": "hT3kq9Vx2LmPzQ8a", "status": "queued" },
>   "meta": { "requestId": "4f8Kq2LmZ7xR1tN9pW3sY", "timestamp": "2026-12-03T09:30:00.000Z" }
> }
> ```
>
> A failure holds `error`, with a `code` to branch on and a `message` to read:
>
> ```json theme={null}
> {
>   "success": false,
>   "error": { "code": "FORBIDDEN", "message": "This API key may not do this." },
>   "meta": { "requestId": "4f8Kq2LmZ7xR1tN9pW3sY", "timestamp": "2026-12-03T09:30:00.000Z" }
> }
> ```
>
> The `X-Request-Id` header holds the same `requestId`. Quote it when you ask for support.

[Errors](https://docs.maqetin.com/api-reference/errors.md) lists every status and code.

## Retries

Retry after a `5xx`, a `429` or a network error, waiting for `Retry-After` when the answer has one. Keep the same `messageId` or `Idempotency-Key`, so a retry never stores an event twice or sends a message twice. Do not retry any other `4xx` as it is: the same request gets the same answer. The one exception is a `401` for an identity token: retry with a new token.


## Related topics

- [SDKs](https://docs.maqetin.com/sdk/overview.md)
- [Maqetin documentation](https://docs.maqetin.com/index.md)
- [Errors](https://docs.maqetin.com/api-reference/errors.md)
- [Contacts](https://docs.maqetin.com/api-reference/contacts.md)
- [Send a message](https://docs.maqetin.com/api-reference/send-message.md)


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