Leave a group

Works on
  • iMessage

Take your line out of a group chat

POST/v1/commands/group.leave

Takes the line out of an iMessage group chat. It is done only in a group chat. Takes no arguments: payload is {} or absent.

Needs a group of four, and is not confirmed

Apple lets a member leave only a group of at least 4 people, the line among them. In a smaller group a group.leave is sent, changes nothing and still ends succeeded. And no leave is confirmed, so after a succeeded or an ambiguous leave the line may still be in the group: check on a phone in the group before you send a leave again. A leave that did happen cannot be undone.

Honors Idempotency-Key: a retry under the same key returns the first leave rather than sending a second.

Body

Target

Prop

Type

Each of these is 422 validation_failed at target.conversationId before anything is sent:

  • a conversation with one person;
  • a conversation no message has arrived in yet;
  • in place of a conversation, the address of someone this project has already exchanged messages with.

The address of someone this project has never exchanged messages with is refused at the field you wrote it at, as on every command done in a conversation.

Payload

None. Any key in payload is 422 validation_failed at that key (payload.<key>) before anything is written.

What comes back

At once, beside the refusals above: 503 upstream_unavailable with details.reason: "connector_unavailable" while the line is offline.

Otherwise 202, then one command event on the response stream:

  • succeeded — the line sent the leave without an error. That means sent, not confirmed: no leave is confirmed. In a group of fewer than 4 people, the line among them, the leave is sent, changes nothing and still ends succeeded: Apple lets a member leave only a group of at least 4.
  • ambiguous with group_leave_unverified — the line's sending errored, so the line may still be in the group.
  • failed with stale_target — the group was addressed right after its membership changed, before its next message. Wait for the next message event from the group, then send the leave again under a new Idempotency-Key.
  • expired with command_expired_before_execution — sending on the line was paused: the line held the leave, and its time ran out before sending resumed. Nothing changed.

Treat succeeded and ambiguous alike: neither proves the line has left the group. After either, check on a phone in the group before you send a leave again.

A succeeded leave also closes the group for your line at once: a conversation.status_changed to closed with reason: "removed", and a send into it is then 409 conversation_closed. If the line is still in the group, the group's next message opens it again.

Example request

curl https://api.mapier.ai/v1/commands/group.leave \
  -H "Authorization: Bearer $MAPIER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: leave-trip-planning" \
  -H "x-mapier-version: 2026-12-01" \
  -d '{
    "target": {
      "kind": "conversation",
      "conversationId": "a0000000-0000-4000-8000-000000000002"
    },
    "payload": {}
  }'

Response

202 Accepted
{
  "commandId": "0192b3e2-81b3-7497-f5c8-a3e06192d487",
  "status": "queued",
  "repeated": false,
  "lineId": "0192a7b0-3e4f-7051-8c6d-7e8f9a0b1c2d",
  "lineSelection": "reused_active_chat"
}

Then, on the response stream, the result of a leave whose sending errored:

event: command — ambiguous
{
  "commandId": "0192b3e2-81b3-7497-f5c8-a3e06192d487",
  "logicalActionId": "leave-trip-planning",
  "status": "ambiguous",
  "errorCode": "group_leave_unverified",
  "conversationId": "a0000000-0000-4000-8000-000000000002",
  "type": "group.leave",
  "messageId": null,
  "externalId": null,
  "namePhoto": null,
  "projectId": "b0000000-0000-4000-8000-000000000002",
  "environment": "live",
  "failureClass": null
}

Errors

Every command can return the errors listed under How commands work › Errors. Specific to this command:

  • 422 validation_failed at target.conversationId for a conversation with one person, one no message has arrived in, or the address of someone this project has already exchanged messages with, in place of a conversation.
  • 422 validation_failed at payload.<key> for any key in the payload.
  • 503 upstream_unavailable with details.reason: "connector_unavailable" while the line is offline.
  • 404 unsupported_command with reason: not_on_channel on a line of any other channel.
  • On a test line on a shared number, 404 unsupported_command with reason: shared_line unless group chats are turned on for your organization, and 403 recipient_not_allowed with group_member_not_test_contact or recipient_must_write_first while someone in the group is not a connected Test contact. See Groups on a test line.

Result codes you will see for this command: group_leave_unverified, stale_target and command_expired_before_execution. See Error codes.

Guide