How commands work
One endpoint for every command, with one envelope, one answer and the rules they share
Every action you take on a line is a command. They all share one endpoint,
one request envelope and one response shape; the {type} path segment names
the command.
Request
Headers
Prop
Type
Body
Prop
Type
The body is capped at 65,536 bytes. Both keys default to {}, so a command
whose whole meaning is its type needs no body at all. A body you do send must
be JSON, and one that is not an object, or whose target or payload is not
an object, is 422 validation_failed. See
Send a message › Who gets it for the target shapes.
Command types
The {type} values the OpenAPI document publishes,
each with its page:
| Type | Purpose | Reference |
|---|---|---|
message.send | Send a message | message.send |
reaction.set | React to a message with one emoji | reaction.set |
reaction.remove | Take back a reaction the line added | reaction.remove |
profile.share | Offer the line's name and photo in a one-to-one conversation | profile.share |
typing.start | Show the typing bubble in a one-to-one conversation the person has written in | typing.start |
conversation.mark_read | Mark the person's messages read in a one-to-one conversation | conversation.mark_read |
message.edit | Change the text of a message the line sent, within 15 minutes | message.edit |
message.unsend | Take back a message the line sent, within 2 minutes | message.unsend |
profile.get | Read the line's own name and photo | profile.get |
profile.set | Set the line's own name and photo | profile.set |
poll.vote | Vote on a poll in a conversation, by the ids its poll.created event carried | poll.vote |
group.create | Start a group chat | group.create |
group.update | Rename a group chat or change its members | group.update |
group.leave | Leave a group chat; it cannot be undone | group.leave |
chat_background.set | Set the background of a conversation, to a preset, two colors of your own or a photo | chat_background.set |
chat_background.remove | Remove the background of a conversation | chat_background.remove |
app_card.update | Replace an iMessage app card your line sent, in place | app_card.update |
| Type | Purpose | Reference |
|---|---|---|
whatsapp.group.create | Make a WhatsApp group and get the invite link people join it by | whatsapp.group.create |
whatsapp.group.create belongs to WhatsApp. Sent to a line on any other
channel, it is 404 unsupported_command with reason: not_on_channel.
A few older command names still work. Each is deprecated, and the page of the command that replaces it says so in one line.
Two refusals, before anything is queued
A type outside the vocabulary is a 404 at once, before the body is read:
{
"error": {
"code": "unsupported_command",
"message": "`message.delete` is not a command Mapier knows."
}
}A type the line cannot carry is a 404 too, raised once the line is resolved
and before anything is written. details.reason says which case it is:
not_on_channel: no line of that channel carries the type.detailsnames thechanneland thecapabilitythe command needed.not_on_line: the channel carries the type and this line reports that it cannot. Ontyping.startorconversation.mark_read, sendoptions.ifUnsupported: "skip"to get200withskipped: trueinstead.
Branch on details.reason, never on message.
Channel support and GET /v1/whoami's
lines[].capabilities say what
each line can do before you send. Older versions answer not_on_line differently; see
Versions › Older versions.
Response
202 Accepted:
{
"commandId": "3f1a0c2e-8b47-4d19-9a5e-2c6f0b8d4e71",
"status": "queued",
"repeated": false,
"lineId": "0192a7b0-3e4f-7051-8c6d-7e8f9a0b1c2d",
"lineSelection": "reused_active_chat"
}lineId is the line the command went out on, as GET /v1/whoami
lists it. lineSelection says why that line: named, reused_active_chat or
new_best_line, explained in The shape of every response.
repeated is true when the Idempotency-Key matched a command already
made: nothing new was queued, and commandId is the first command's.
status is "queued" on every 202, a repeat included. It says the command
was accepted, never how it ended. A repeated key with nothing to return is not
a 202 at all: a message.send whose first attempt is still running, or that
no channel ever took, is a 409 conflict (see Errors).
The response tells you the command was queued. It does not tell you the message was delivered.
Watch the response stream for the command event that ends it.
Idempotency
Every command honors Idempotency-Key: a repeat of a key returns the first
command and never runs it twice. A message.send is recorded against its key
by Mapier before the line is asked, so a retried send is never posted twice. It
is returned when a channel took the first attempt, and refused with
409 conflict when none did. A retry of an attempt that got no answer is
409 conflict with reason: idempotency_key_in_flight while it may still be
running, and idempotency_key_unresolved after. It is never sent again.
The result's logicalActionId carries your key. On an iMessage line,
group.create carries a copy of its commandId instead. Correlate by
commandId. See Idempotency and retries.
What is checked before anything is queued
The body first: over 65,536 bytes is 413 payload_too_large, and not JSON is
400 bad_request. A body, target or payload that is not an object is
422 validation_failed. So is a target that names nobody (at
target.recipientExternalId), and an Idempotency-Key that is empty, over 200
characters, holds a control character or has whitespace at either end (at
Idempotency-Key).
A message.send payload is checked against the line the send resolves to. A
key the line does not carry that carries a value, a kind or a misspelled
field included, is 422 validation_failed at payload.<key>. So is a send
with no text, at payload.text. See
What a line carries. An iMessage line
also refuses what the conversation cannot carry, with the same code and nothing
written; Send a message › Who gets it lists
each case:
- an email address sent to someone the line has no conversation with, at the target field you wrote it at;
- a group chat the channel has not reported yet, at
target.conversationId; - a reply the line cannot quote, at
target.replyToMessageId.
On an iMessage line Mapier also checks how other commands are addressed, and
refuses each with 422 validation_failed before anything is sent:
- a
profile.sharenames, attarget.conversationId, a conversation the person has written in; - a
group.createnames 2 to 32 other people attarget.participantExternalIds, each an address the channel reads, counted once. The first is the command's recipient. One the channel cannot read, the first included, is refused attarget.participantExternalIds[i](or the key and index you wrote); - a
group.updateor agroup.leavenames, attarget.conversationId, a group chat. An update's action and itsnameorparticipantExternalIdare checked too, and a leave's payload must be empty; - a
chat_background.setor achat_background.removenames, attarget.conversationId, a one-to-one conversation the person has written in, or a group chat. A set'spayload.preset,payload.colorsandpayload.photoUrlare checked too, and a remove's payload must be empty; - a
message.editor amessage.unsendnames, attarget.messageId, a message this line sent in that conversation, which has a channel id and is inside its window. An edit'spayload.textis checked too; - a
profile.getor aprofile.setnames, attarget.lineId, one of your project's lines (any other id is403 line_not_allowed). A set's payload is checked too, and its photo link fetched; - a
message.send, or any command addressed to a person, that names a line attarget.lineIdnames one of your project's lines (any other id is403 line_not_allowed), on the channeltarget.channelnames if it names one and, beside aconversationId, the line that conversation is on; - a
typing.startnames, attarget.conversationId, a one-to-one conversation the person has written in; - a
conversation.mark_readnames the same, and an optionalpayload.externalIdis checked too; - a
poll.votenames, attarget.conversationId, a conversation the person has written in, a group's included, and the poll and the choice atpayload.pollExternalIdandpayload.optionExternalId.payload.removeand any other key are refused; - an
app_card.updatenames, attarget.messageId, a card your line sent, any update of it, or a card the person sent that replaced it. Itsurlandlayoutare checked too, and a card that cannot be updated is refused withreason: card_not_updatable. Amessage.sendofkind: "app_card"names, atpayload.app, an app your organization holds, by its registered name.
Mapier checks no other command's payload. The channel checks profile.share
before it takes it, and that refusal comes back as a 422 validation_failed
too, or a 400 bad_request, with the channel's word as the reason. A
group.create payload is otherwise checked only when the line runs it. So in a
profile.share or group.create payload, a misspelled field, an out-of-range value or a bad enum
can return 202 and end failed on the stream seconds later. When you are
developing against a new payload shape, keep the stream open.
A sticker and a link are
checked by Mapier as a text is: every bound at its own field,
422 validation_failed before anything is queued. What the line can still
refuse is its own capability: the result ends failed with
capability_constraint_violation.
Errors
| Status | Code | Cause |
|---|---|---|
400 | bad_request | Body is not JSON, or the channel refused the request as malformed (details.reason is its word); or, with a personal access token, no x-mapier-project header |
401 | invalid_credentials | No key, or one that is unknown, revoked or expired |
403 | forbidden | A personal access token not made for this environment, or whose owner's role no longer allows this |
403 | insufficient_scope | The key does not carry the messages:send scope |
403 | line_not_allowed | target.lineId is not one of your project's lines; details.reason is not_owned and details.lineId the id sent. GET /v1/whoami lists the lines the key can use |
403 | recipient_not_allowed | The person cannot be sent to: details.reason is opted_out, blocked, paused, outside_service_window, recipient_must_write_first (no one but your line has written in the conversation, or on a test line on a shared number the person is not connected) app_card_needs_imessage (an app card into a conversation whose newest message did not go by iMessage) or group_member_not_test_contact (on a test line on a shared number, someone in the group is not one of this project's connected Test contacts) |
404 | unsupported_command | Unknown {type}, or one the line cannot carry: details.reason is not_on_channel (no line of the channel carries it) not_on_line (this line does not) or shared_line (a test line on a shared number does not) |
404 | not_found | Unknown conversation, or another project's |
409 | conflict | The Idempotency-Key is taken and there is nothing to return, and details.reason says why: idempotency_key_in_flight (the first attempt is still running: wait, and retry with the same key), idempotency_key_failed (it was refused and not sent: send again under a new key, only the parts not in details.sentParts when it names any), idempotency_key_unresolved (its outcome is unknown: check the conversation first) or idempotency_key_reused (the key already named a different command). For app_card.update, card_update_in_flight: the card's last send has not finished; wait for its result and send the update again. Or the channel refused the command for a reason of its own, such as group_has_no_messages_yet (a member change in a group with no message yet: send a message into it first); such a reason may add details.retryAfter, the seconds to wait. See Idempotency and retries |
409 | conversation_closed | The group is closed: your line can no longer reach it, and nothing was sent. details.reason is removed, deleted, archived or suspended, and details.conversationId names the group. It lifts once the group is active again; see Groups |
409 | limit_reached | A daily cap on this line is reached; today only a test line on a shared number has one |
409 | project_archived | The project is archived |
413 | payload_too_large | Body over 65,536 bytes |
422 | validation_failed | A field is wrong, and details names it: a non-object body, an Idempotency-Key outside its rule, a message.send field the line does not carry, or an address, reply, conversation, message, participant, line or payload a command cannot be addressed by (see What is checked) |
429 | rate_limited | 600 requests per minute, per project by default; GET /v1/whoami reports your project's own (see Rate limits). The Retry-After header says how long to wait (a channel's own rate limit may give the same seconds in details.retryAfter too). On a test line on a shared number, details.reason shared_line is that line's own budget. For app_card.update, card_update_limit: the card has had 50 updates in the past hour; wait details.retryAfter seconds |
429 | sandbox_budget_exhausted | Not returned today. Handle it like rate_limited |
500 | internal_error | An unexpected error on Mapier's side; quote the error's requestId to support |
503 | no_line | No active line on the channel |
503 | capacity_exhausted | Every line is full |
503 | line_unavailable | The line cannot send right now: details.reason is line_paused, line_retired, transport_down, transport_unconfigured or channel_not_available |
503 | upstream_unavailable | The channel did not take the command: details.reason is its word, such as connector_unavailable (the line is offline) or outbound_paused (sending is paused), or timeout, network or status_5xx when no usable answer came back. A message.send's key is then spent: resend it under a new key |
503 | service_busy | Mapier was too busy to take the request and did nothing; wait details.retryAfter seconds and send the same request |
Older versions use other words for two of these; see Versions › Older versions. Full descriptions and retry guidance: Error codes.