Send and read iMessage and SMS: messages and chats
Send iMessage and SMS from a bubblr line, follow delivery, send photos and files, react, show typing, and read and search conversations.
A line sends iMessage to people who have it and a text message (SMS, or RCS where available) to everyone else. You send the same way either way; the message says how it went.
Who you can send to
to takes a phone number, an email address (iMessage only) or a group chat's id.
- US and Canadian numbers need no
+1:(415) 555-0142,415-555-0142and+14155550142are the same person and the same conversation. - Other countries need their
+country code. - Group chats: use the chat's
handlefromGET …/chats.
Sending
curl -X POST https://api.bubblr.io/v1/profiles/prf_2Wq8nT4kLm/messages \
-H "Authorization: Bearer $BUBBLR_API_KEY" -H "Idempotency-Key: $(uuidgen)" -H "Content-Type: application/json" \
-d '{"to": "+14155550142", "text": "Your order is ready for pickup."}'| Field | |
|---|---|
to |
Who to send to (required). |
text |
Up to 20,000 characters. A send needs text, attachments, or both. |
attachments |
Up to 10 photos or files (below). |
service |
iMessage, RCS or SMS to force one. Leave it out to let the line choose. |
reply_to |
A msg_… to reply to inline. |
effect |
An iMessage effect: slam, loud, gentle, invisible-ink, confetti, echo, fireworks, balloons, love, lasers, celebration, shooting-star, spotlight. |
queue, queue_minutes |
What happens while the line has trouble (below). |
A key that covers exactly one line can leave the line out: POST /v1/messages.
The answer is always 202 Accepted with the message, status: "queued". Sending happens right after.
Idempotency
Every send needs an Idempotency-Key header, any unique string up to 255 characters. Retrying with the same key and
the same body answers the same message (with Idempotent-Replayed: true) and never sends it twice, so a timeout or a
crash between your request and our answer can't double-text someone. The same key with a different body is
409 idempotency_key_reused: nothing was sent. The SDK makes keys for you.
Following a message
status |
Means |
|---|---|
queued |
Waiting to go out. |
dispatched |
On its way. |
sent |
Sent. service says how: iMessage, RCS or SMS. |
delivered |
Reached the person's device. |
read |
They read it (iMessage, when they share read receipts). |
failed |
Not sent; error.code says why. |
unconfirmed |
We couldn't confirm it went out. Check with the person before sending it again. |
received |
A message someone sent to the line. |
Each step is also an event (message.sent, message.delivered, message.read, message.failed), by
webhook or the live stream. When iMessage can't reach someone, the line sends the message again as
a text: you get message.fallback, then message.sent with the new service, and the message's fallback_from
says iMessage.
Failure codes in error.code: line_unavailable (the line had trouble longer than the queue window),
recipient_not_allowed (the key's guardrails), unconfirmed, send_failed.
While the line has trouble
A line's state is working most of the time. When it's having_trouble, sends wait in the queue (status: queued, with queue_until) and go out once the line is back. After queue_minutes (default 15, up to 1,440) they
fail with line_unavailable. Send with "queue": false to get 503 line_unavailable at once instead, for
messages that are only worth sending now. GET /v1/profiles/{profile_id}/status shows the queue.
Photos and files
Send files from a public https:// URL:
{ "to": "+14155550142", "text": "Here's the floor plan", "attachments": [{ "url": "https://example.com/floorplan.pdf" }] }Or upload them first, for files that aren't public:
POST /v1/profiles/{profile_id}/uploadswithfile_name,mime_typeandsize_bytes. The answer has anupload_urland anid(upl_…).PUTthe file's bytes toupload_urlwithin 15 minutes.- Send with
"attachments": [{ "upload_id": "upl_…" }]. An upload can be sent for 7 days.
Messages list their files in attachments, each with a url like /v1/attachments/att_…. GET it with your key:
the answer is a 302 to a short-lived download link. Ask again each time rather than storing the link.
Reading conversations
# The line's chats, most recent first, with each chat's newest message and unread count
curl "https://api.bubblr.io/v1/profiles/prf_2Wq8nT4kLm/chats?limit=20" -H "Authorization: Bearer $BUBBLR_API_KEY"
# The chat with one person, by their number in any format
curl "https://api.bubblr.io/v1/profiles/prf_2Wq8nT4kLm/chats?handle=4155550142" -H "Authorization: Bearer $BUBBLR_API_KEY"
# A chat's messages, newest first
curl "https://api.bubblr.io/v1/profiles/prf_2Wq8nT4kLm/chats/cht_5Rf1sD8hJw/messages" -H "Authorization: Bearer $BUBBLR_API_KEY"
# Search every message on the line
curl "https://api.bubblr.io/v1/profiles/prf_2Wq8nT4kLm/messages?q=invoice" -H "Authorization: Bearer $BUBBLR_API_KEY"Reading works while the line has trouble. Chats carry contact, the name and tags your team gave the person (see
contacts), and filter by tag and assigned_to.
Pages
Messages, chats, drafts, calls and contacts come newest first, limit at a time (default 50, up to 200). When
has_more is true, pass the answer's next_before as before for the next page:
curl "https://api.bubblr.io/v1/profiles/prf_2Wq8nT4kLm/messages?limit=100&before=msg_9KxT3vQ7Pa" -H "Authorization: Bearer $BUBBLR_API_KEY"The SDK does this for you: for await (const m of bubblr.messages.list({ profile_id })).
Reactions, typing and read receipts
These reach the other person at once, so they need the line working (503 line_unavailable otherwise):
- React:
POST …/messages/{message_id}/reactions {"reaction": "love"}:love,like,dislike,laugh,emphasizeorquestion;"remove": truetakes it back. iMessage only (409 imessage_only). Reactions people send arrive asmessage.reactionevents, and every message lists itsreactions. - Typing:
POST /v1/profiles/{profile_id}/typing {"chat_id": "cht_…"}shows the typing indicator;"typing": falsestops it. - Mark read:
POST …/chats/{chat_id}/readmarks the chat read, which sends read receipts if the line has them on. To clear the unread count without telling the other person,PATCH …/chats/{chat_id} {"seen": true}.
Handing chats between agents and people
PATCH /v1/profiles/{profile_id}/chats/{chat_id} {"assigned_to": "human"} marks who handles a chat: agent,
human or null. It sends chat.updated, shows in the app's inbox, and lists filter on it
(?assigned_to=agent). A common pattern: your agent answers chats assigned to agent (or nobody) and leaves the
rest to your team.
For agents that should never send without a person's approval, see draft-only keys.