---
name: mapier
description: Send and receive messages for an AI agent through Mapier's /v1 API — one set of commands and one event stream on every channel Mapier offers. Use when writing or debugging code that calls api.mapier.ai.
---

# Mapier messaging API

Base URL: `https://api.mapier.ai`. Every request carries `Authorization: Bearer <key>` and `x-mapier-version: 2026-12-01`.

## Before you send

1. Ask your user for an API key. They create one on the **Keys** page of the console at https://convo.mapier.ai/app. Read it from an environment variable, and keep it out of code and logs.
2. The key sends from your user's real lines, so every message you send reaches a real person. While you build and test, send only in the conversation your user starts by messaging their line.
3. Never ask your user for a channel secret, such as a bot token or app secret. It goes only into the console.

## Rules

1. Send an `Idempotency-Key` and an `x-mapier-version` header on every command. The key is optional, but without one a retry is a second send.
2. A `202` means queued, not delivered. Read the result on `GET /v1/response_stream`.
3. Check a feature before you promise it. `GET /v1/capabilities` covers every channel, `lines[].capabilities` on `GET /v1/whoami` covers one line, and `POST /v1/commands/{type}/check` covers one call. If a request is refused, read `error.details` and follow its `remedy` when it has one.
4. Reply with `target.conversationId`. On a new send, name `target.channel`.
5. Never fall back to another channel, and never resend a command whose result is `ambiguous`.
6. On WhatsApp, send a free-form message only within 24 hours of the person's last message; outside it, and to write first, send an approved template with `message.send` and `kind: "template"`.
7. Look up any error code at `https://docs.mapier.ai/convo/api/errors/<code>`.
8. Before you message someone, ask `GET /v1/reachability` whether the line can reach them now; a refused send carries the same answer at `error.details.reachability`.

## The loop

1. `GET /v1/whoami`: the key's project, and its lines with their `channel` and `capabilities`.
2. Open `GET /v1/response_stream` and keep it open. Or receive the same events at a webhook endpoint, made on the console's **Webhooks** page, where a `command` event is `command.settled` and a `message` event is `message.received`.
3. `POST /v1/commands/<type>` with `target` and `payload`. A `202` is a `commandId`, nothing more.
4. Read the `command` event for that `commandId`, and `message` events for replies. The command is done when its result arrives there, not at the `202`.
5. Every stream event carries `id:`. Handle each one once, by its `id`: one can arrive twice across a reconnect. Reconnect with the last one you handled as `Last-Event-ID`, and the stream sends what you missed.

## Received messages

A received message's `text` is null when it carries only attachments: fetch each one with `GET /v1/attachments/{id}`. On an iMessage line whose device predates the chat background event, a chat background change in a one-to-one conversation arrives as a received message with no text. Skip a received message that has no text and no attachment rather than reply to it.

## Connecting a line

With a `lines:write` key, start a setup with `POST /v1/line-setups`. Give your user its `handoffUrl`, where they enter the channel's secrets.

## Channels

- **iMessage** (Available): Your agent texts from a US number Mapier provides. Connect: https://docs.mapier.ai/convo/guides/connect/imessage.md · Everything: https://docs.mapier.ai/llms/imessage.txt
- **WhatsApp** (Beta): Connect a WhatsApp Business number you own. Connect: https://docs.mapier.ai/convo/guides/connect/whatsapp.md · Everything: https://docs.mapier.ai/llms/whatsapp.txt

What works on each channel, one table: https://docs.mapier.ai/convo/api/channel-support.md

## Files

- Every page as markdown: append `.md` to its URL. Index: https://docs.mapier.ai/llms.txt
- Every page in one file: https://docs.mapier.ai/llms-full.txt
- Every `/v1` request and response: https://api.mapier.ai/openapi.json
- What each channel supports, as data: https://docs.mapier.ai/capabilities.json. `GET /v1/capabilities` is the live version.
- Errors, one row per code, each linking its own page: https://docs.mapier.ai/convo/api/errors.md
