Set a background

Works on
  • iMessage

Set a conversation's background to a preset, two colors or a photo

POST/v1/commands/chat_background.set

Sets the background of an iMessage conversation, by the background's name at payload.preset: one of Apple's own backgrounds, custom with two colors you choose, or photo with a picture of your own at a link. It is done in a one-to-one conversation the person has written in, or in a group chat.

Honors Idempotency-Key: a retry under the same key returns the first command without fetching the link again, rather than setting the background again, even when the retry names another photoUrl. A set and a chat_background.remove each take a key of their own — see One key for each command.

A change is reported as an event

Every background change, this command's or one a person makes on their own phone, is reported as a conversation.background_changed event, opt-in, and as a chat_background event on a stream opened with ?events=chat_backgrounds. A line on older software instead leaves a message with no text — see What a change reports.

Body

Target

Prop

Type

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

  • a conversation no message has arrived in yet;
  • a one-to-one conversation the line has not yet confirmed, with reason: conversation_not_confirmed — send the person a text first;
  • 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

Prop

Type

Presets

A preset's name is lower-case and sent exactly as written here.

PresetWhat it is
gradientApple's default background.
color_mango, color_ice, color_plum, color_deep_sea, color_green_apple, color_cherry, color_bubblegum, color_tangerine, color_magenta, color_lime, color_silver, color_carbon, color_stoneApple's two-color gradients, by Apple's name for each.
customA gradient of the two colors you give at colors.
aurora_green, aurora_purple, aurora_pinkApple's animated aurora backgrounds.
sky_dusk, sky_haze, sky_sunset, sky_clear, sky_sunrise, sky_dawnApple's animated sky backgrounds.
water_light, water_darkApple's animated water backgrounds.
glitter_gold, glitter_copper, glitter_silverApple's animated glitter backgrounds.
photoA picture of your own, from the link at photoUrl.

Colors of your own

custom is a gradient of two colors, given at payload.colors as an array of exactly two strings, each #RRGGBB:

{ "preset": "custom", "colors": ["#008080", "#FFE600"] }

Every other preset has its own colors and takes no colors.

A photo of your own

photo makes a picture of your own the background. Give it at payload.photoUrl, as an https link:

{ "preset": "photo", "photoUrl": "https://example.com/backgrounds/harbour.jpg" }
  • The link is https and at most 2048 characters.
  • The picture is a JPEG, PNG, HEIC/HEIF or WebP image of at most 8 MiB and 100 megapixels, no side over 65,535 px. A GIF is refused.
  • Mapier fetches the link and hands the picture to the line before anything is sent. A link it cannot use is refused at once, and nothing is sent.

The line re-encodes it as a JPEG whose long side is at most 3,072 px. Transparent areas become white. The person sees it behind the messages, cropped to fill the screen, in Apple's Original look with no color filter. To know what they will see, send a JPEG of at most 3,072 px on its long side, with no transparency.

Every other preset takes no photoUrl.

What is refused

Each of these is 422 validation_failed before anything is sent:

  • a preset that is missing or not on that list, at payload.preset;
  • a custom set without exactly two #RRGGBB colors, at payload.colors;
  • colors beside any other preset, at payload.colors;
  • a photo set without an https link of at most 2048 characters, at payload.photoUrl;
  • photoUrl beside any other preset, at payload.photoUrl;
  • a link that cannot be fetched, or a file that is not a JPEG, PNG, HEIC/HEIF or WebP image, is over 8 MiB or 100 megapixels, or has a side over 65,535 px, at payload.photoUrl, its reason one of the link refusals a media send meets: media_fetch_refused, media_fetch_failed, media_too_large or unsupported_media_type. Rarely, the line refuses a picture Mapier took, and the reason is image_too_large or unreadable_image;
  • any other key, at that key (payload.<key>).

What comes back

At once, beside the refusals above, the line can answer 503 upstream_unavailable:

  • with details.reason: "connector_unavailable" while the line is offline;
  • with details.reason: "outbound_paused" while sending on the line is paused.

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

  • succeeded — the line made the change and confirmed it.
  • failed with gateway_rejected — the line refused before changing anything: it was busy with another background change, could not find the conversation, or was not ready to change a background. Nothing changed, and the set can be sent again under a new Idempotency-Key. For a photo it can also mean the line could not read the picture: sending the same picture again fails the same way.
  • failed with transfer_not_landed — a photo set only: the picture did not reach the line within five minutes. Nothing changed.
  • failed with invalid_target — a photo set only: the picture was no longer on the line when the change began. Nothing changed.
  • failed with stale_target — the line could not find the group chat with the members it last saw, as happens right after the membership changed and before the group's next message.
  • failed with capability_not_negotiated — the line does not support setting a background. Setting and removing are supported separately.
  • failed with capability_constraint_violation — the line does not carry that preset. Nothing changed. See A preset the line does not carry.
  • expired with command_expired_before_execution — the line did not reach the change in time. Nothing changed.
  • ambiguous with chat_background_unverified — the line began the change and could not confirm it. It may or may not have been made.

Rarely, a set ends ambiguous with gateway_timeout instead, when the attempt failed before the line could say what it did. Read it as chat_background_unverified.

chat_background_unverified: ask before you send it again

This API cannot read a background back. Ask someone in the conversation whether the background changed before you send the set again.

Succeeded does not mean the person sees it

A phone can keep a background from a sender it has no contact for and show nothing. This is most likely in a new conversation with one person, until the line is a saved contact on their phone. succeeded says the line made the change and confirmed it, not that the person sees it. When it matters, ask them.

A preset the line does not carry

A line on older software supports fewer backgrounds. A set of a preset the line does not support is accepted and then ends failed with capability_constraint_violation and failureClass: "capability". Nothing changed.

gradient is on every line that sets a background, so it is the one to fall back to.

photo is the newest. A line that has not been updated for it ends a photo set failed with capability_constraint_violation. Nothing changed.

While a change is under way

A background change lets the line's other waiting commands go first. Once it has started, the line runs nothing else until the change is confirmed or given up on, so anything sent meanwhile but a typing.start, into any conversation on the line, waits for it.

A message on the conversation path, a reaction, a profile.share or a poll.vote that waits longer than that path's 30 seconds ends expired.

What a change reports

Every change to a conversation's background, this command's or one a person makes on their own phone, is reported as a conversation.background_changed event, and as a chat_background event on a stream opened with ?events=chat_backgrounds. Both are opt-in: subscribe a webhook endpoint to the type by name, or open the stream with the option.

Your own change arrives there with fromMe: true and from set to the line's own address, as well as in this command's command event: one change, reported twice, so do not count it twice. background is null for a removal. On a set it names the preset, or null when the line could not tell which background was set — so a set followed at once by another can report preset: null — and a photo by its preset, with the picture's attachmentId to fetch from GET /v1/attachments/{attachmentId} when the line could export it. A change in a group chat is reported the same way, on the group's conversation. See Chat background events.

On a line that predates the event

A line whose device is on older software reports a background change in a conversation with one person differently: it leaves a message from that person with no text, whoever made the change — this command, or the person on their own phone. It is a message event and a message.received webhook whose text is null. It is stored in the conversation, counted as a received message, and leaves the conversation awaiting a reply in the console until the line next sends.

Nobody wrote anything, so there is nothing to answer. Skip a received message that has no text and no attachment rather than reply to it — see Inbound message events and Webhooks.

On such a line, a change the line makes in a group chat produces no message and no event.

One key for each command

Give a set and a remove a key each. The two count as one command for the key: one Idempotency-Key reused across a set and a remove is answered with the first command and changes nothing more.

Example request

curl https://api.mapier.ai/v1/commands/chat_background.set \
  -H "Authorization: Bearer $MAPIER_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: background-set-order-2481" \
  -H "x-mapier-version: 2026-12-01" \
  -d '{
    "target": {
      "kind": "conversation",
      "conversationId": "a0000000-0000-4000-8000-000000000001"
    },
    "payload": { "preset": "sky_dusk" }
  }'

Response

202 Accepted
{
  "commandId": "0192b3e2-70a2-7386-e4b7-92df5081c376",
  "status": "queued",
  "repeated": false,
  "lineId": "0192a7b0-3e4f-7051-8c6d-7e8f9a0b1c2d",
  "lineSelection": "reused_active_chat"
}

Then, on the response stream:

event: command — succeeded
{
  "commandId": "0192b3e2-70a2-7386-e4b7-92df5081c376",
  "logicalActionId": "background-set-order-2481",
  "status": "succeeded",
  "errorCode": null,
  "conversationId": "a0000000-0000-4000-8000-000000000001",
  "type": "chat_background.set",
  "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 no message has arrived in, a one-to-one conversation the line has not confirmed (with reason: conversation_not_confirmed), or the address of someone this project has already exchanged messages with, in place of a conversation.
  • 422 validation_failed at payload.preset, payload.colors, payload.photoUrl or payload.<key>, as above.
  • 503 upstream_unavailable with details.reason: "connector_unavailable" while the line is offline, or "outbound_paused" while sending on the line is paused.
  • 404 unsupported_command with reason: not_on_channel on a line of any other channel.

Result codes you will see for this command: gateway_rejected, transfer_not_landed, invalid_target, stale_target, capability_not_negotiated, capability_constraint_violation, command_expired_before_execution, chat_background_unverified and gateway_timeout. See Error codes.

Guide