How commands work

One endpoint for every command, with one envelope, one answer and the rules they share

POST/v1/commands/{type}

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:

TypePurposeReference
message.sendSend a messagemessage.send
reaction.setReact to a message with one emojireaction.set
reaction.removeTake back a reaction the line addedreaction.remove
profile.shareOffer the line's name and photo in a one-to-one conversationprofile.share
typing.startShow the typing bubble in a one-to-one conversation the person has written intyping.start
conversation.mark_readMark the person's messages read in a one-to-one conversationconversation.mark_read
message.editChange the text of a message the line sent, within 15 minutesmessage.edit
message.unsendTake back a message the line sent, within 2 minutesmessage.unsend
profile.getRead the line's own name and photoprofile.get
profile.setSet the line's own name and photoprofile.set
poll.voteVote on a poll in a conversation, by the ids its poll.created event carriedpoll.vote
group.createStart a group chatgroup.create
group.updateRename a group chat or change its membersgroup.update
group.leaveLeave a group chat; it cannot be undonegroup.leave
chat_background.setSet the background of a conversation, to a preset, two colors of your own or a photochat_background.set
chat_background.removeRemove the background of a conversationchat_background.remove
app_card.updateReplace an iMessage app card your line sent, in placeapp_card.update
TypePurposeReference
whatsapp.group.createMake a WhatsApp group and get the invite link people join it bywhatsapp.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:

POST /v1/commands/message.delete — 404
{
  "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. details names the channel and the capability the command needed.
  • not_on_line: the channel carries the type and this line reports that it cannot. On typing.start or conversation.mark_read, send options.ifUnsupported: "skip" to get 200 with skipped: true instead.

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.share names, at target.conversationId, a conversation the person has written in;
  • a group.create names 2 to 32 other people at target.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 at target.participantExternalIds[i] (or the key and index you wrote);
  • a group.update or a group.leave names, at target.conversationId, a group chat. An update's action and its name or participantExternalId are checked too, and a leave's payload must be empty;
  • a chat_background.set or a chat_background.remove names, at target.conversationId, a one-to-one conversation the person has written in, or a group chat. A set's payload.preset, payload.colors and payload.photoUrl are checked too, and a remove's payload must be empty;
  • a message.edit or a message.unsend names, at target.messageId, a message this line sent in that conversation, which has a channel id and is inside its window. An edit's payload.text is checked too;
  • a profile.get or a profile.set names, at target.lineId, one of your project's lines (any other id is 403 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 at target.lineId names one of your project's lines (any other id is 403 line_not_allowed), on the channel target.channel names if it names one and, beside a conversationId, the line that conversation is on;
  • a typing.start names, at target.conversationId, a one-to-one conversation the person has written in;
  • a conversation.mark_read names the same, and an optional payload.externalId is checked too;
  • a poll.vote names, at target.conversationId, a conversation the person has written in, a group's included, and the poll and the choice at payload.pollExternalId and payload.optionExternalId. payload.remove and any other key are refused;
  • an app_card.update names, at target.messageId, a card your line sent, any update of it, or a card the person sent that replaced it. Its url and layout are checked too, and a card that cannot be updated is refused with reason: card_not_updatable. A message.send of kind: "app_card" names, at payload.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

StatusCodeCause
400bad_requestBody 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
401invalid_credentialsNo key, or one that is unknown, revoked or expired
403forbiddenA personal access token not made for this environment, or whose owner's role no longer allows this
403insufficient_scopeThe key does not carry the messages:send scope
403line_not_allowedtarget.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
403recipient_not_allowedThe 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)
404unsupported_commandUnknown {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)
404not_foundUnknown conversation, or another project's
409conflictThe 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
409conversation_closedThe 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
409limit_reachedA daily cap on this line is reached; today only a test line on a shared number has one
409project_archivedThe project is archived
413payload_too_largeBody over 65,536 bytes
422validation_failedA 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)
429rate_limited600 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
429sandbox_budget_exhaustedNot returned today. Handle it like rate_limited
500internal_errorAn unexpected error on Mapier's side; quote the error's requestId to support
503no_lineNo active line on the channel
503capacity_exhaustedEvery line is full
503line_unavailableThe line cannot send right now: details.reason is line_paused, line_retired, transport_down, transport_unconfigured or channel_not_available
503upstream_unavailableThe 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
503service_busyMapier 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.

Guide