OAuth for iCloud developer guide

Prevent Duplicate iMessages After a Timeout

Send every message with a stable Idempotency-Key header. After a timeout or an unknown state, poll the receipt endpoint with the same key instead of sending again.

Figment editorial teamPublished Updated Facts checked November 11, 2026

To avoid duplicate iMessages, attach a stable Idempotency-Key header to every send. After a timeout or an unknown response, poll the receipt endpoint with the same key before you consider retrying.

A network timeout tells you one thing: you stopped waiting. It says nothing about whether the bridge accepted your request. By the time your client dropped the connection, the Mac worker may already have handed your message to Apple's iMessage infrastructure. If you issue a second POST with fresh parameters, the bridge has no basis to link it to the first, so it enqueues a second delivery.

What scope and chatGuid does a send need?

The messages:send scope is separate from messages:read and must be requested explicitly during the OAuth authorization step. It grants access only to selected existing conversations. A conversation that appears in a read result is not automatically authorized for sends, so your send grant must include that specific thread.

Every chatGuid value in a send or read request must come from the chat list API. Do not construct or guess these values.

How do I generate the idempotency key?

Create one key per intended send, freeze the exact request payload, and write both to your own durable store before the first HTTP call. If your process crashes mid-flight, you need that key to poll the receipt later. A pending action carries no guaranteed server-side retention, so your store is the source of truth.

Do not compute the key from a hash of the message body. Two separately intended sends of identical text would share a hash and merge into a single delivery. Encode intent with a unique component:

{appId}-{connectionId}-{conversationRef}-{uuid}

For example: app_x9a-con_abc123-thread_home-01JDF3. Never generate a new key when retrying the same intent. A new key signals a new intent, and the bridge treats it as a fresh request, which risks a second delivery. Failures or validation can stop either request.

How do I send with the Idempotency-Key header?

POST https://figment.so/api/icloud/v1/connections/con_abc123/messages/send
Authorization: Bearer ACCESS_TOKEN
Content-Type: application/json
Idempotency-Key: app_x9a-con_abc123-thread_home-01JDF3

{
  "chatGuid": "CHAT_GUID_FROM_LIST_API",
  "text": "Your order shipped."
}

The bridge binds the key to this connection and the exact request body. A later POST with the same key and unchanged body returns the original recorded outcome without delivering again, and the response carries "replayed": true. If the body changes while the key stays the same, the request is rejected. A changed payload during retry must stop, not silently mint a new key. Use a new key only for an explicitly approved new action, not to handle an uncertain retry.

One example of a first-send response in live mode:

{
  "data": {
    "idempotencyKey": "app_x9a-con_abc123-thread_home-01JDF3",
    "state": "submitted",
    "retrySend": false
  },
  "mode": "live",
  "replayed": false
}

state: submitted means the Mac accepted the message. It is not proof of delivery to the recipient's device. In sandbox mode, the state is simulated and no real message is sent:

{
  "data": {
    "idempotencyKey": "app_x9a-con_abc123-thread_home-01JDF3",
    "state": "simulated",
    "delivery": "simulated",
    "retrySend": false
  },
  "mode": "sandbox",
  "replayed": false
}

What should I do after a timeout or an unknown response?

Do not issue a new send. Poll the receipt endpoint with the same Idempotency-Key:

GET https://figment.so/api/icloud/v1/connections/con_abc123/messages/receipt
Authorization: Bearer ACCESS_TOKEN
Idempotency-Key: app_x9a-con_abc123-thread_home-01JDF3
StateMeaningYour next action
submittedMac is processingRe-poll; treat as in-flight
deliveredDelivered to recipient's deviceNo retry needed
readRecipient opened the messageNo retry needed
failedSend action recorded as failedSame key returns the recorded failure, not a new attempt; decide independently whether to start a new action under a new key
unknownOutcome indeterminateRe-poll after a brief wait; never resend under a new key
simulatedSandbox synthetic receiptNo real delivery occurred

A client-side timeout with no response is functionally unknown. Treat it as such and re-poll with the original key.

Which test cases should I run?

These seven scenarios cover the edge cases that can produce duplicates or unexpected behavior:

#ScenarioSame key on retry?Body changed?Expected result
1First send; clean response——Live: current receipt state (e.g. submitted); sandbox: simulated; replayed: false
2Client timeout; retry with identical requestYesNoSame recorded outcome; replayed: true
3Retry with edited text; same keyYesYesRequest rejected: fix the body, or generate a new key only for an explicitly approved new action
4unknown; receipt transitions to delivered——No retry needed
5unknown; receipt remains unknown after sync settles——Re-poll; check Mac connection readiness before escalating
6Two workers race to retry with the same key and bodyYesNoConcurrent-retry behavior is not independently verified; treat this as an integration test requirement before relying on it in production
7New distinct message after confirmed deliveryNo, new keyNew bodyNew delivery; generate a fresh key before the first attempt

Scenario 6 matters when retry logic runs across distributed workers. Verify concurrent-retry behavior in your own integration tests, and do not assume a specific outcome before testing.

Does this also apply to SMS, MMS, and RCS threads?

Yes, the same idempotency pattern applies. Messages in iCloud includes forwarding when enabled, and the iPhone must be powered on, online, and signed into the same Apple Account (Apple: Use Text Message Forwarding). An unknown state on a carrier thread may reflect an iPhone connectivity issue rather than a bridge failure. Unknown remains unknown until receipt evidence resolves it.

What does OAuth for iCloud cost?

Sandbox is free. Messages is part of the Full iCloud suite, which costs the developer $29/month per connected Apple Account. For live access, request a demo. Connect an Apple Account to start building in the sandbox.

Connect Apple data to your app

Register your app and start with synthetic sandbox data. Choose the permissions your app needs.

Connect Apple Account

Sandbox is free. Live access is $14 or $29 per connected Apple Account, per month.