sendblue-api
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSendblue API
Sendblue API
Overview
概述
Sendblue is a REST API that sends iMessage (blue bubbles), SMS, and RCS from a provisioned phone number. Everything is plain JSON over HTTPS — no SDK is required. The API covers outbound 1:1 and group sends, iMessage effects, reactions, typing indicators, status callbacks, and inbound webhooks.
Sendblue是一款REST API,可通过已配置的电话号码发送iMessage(蓝色气泡消息)、SMS和RCS消息。所有交互均基于HTTPS传输纯JSON数据——无需使用SDK。该API支持一对一及群组消息发送、iMessage特效、消息反应、输入状态提示、状态回调以及入站Webhook功能。
When to Use This Skill
何时使用该技能
- Use when writing application code (server, worker, function) that sends Sendblue messages as part of a long-running service.
- Use when receiving inbound messages via webhooks.
- Use when you need features the CLI does not expose: send styles, reactions, group messages, typing indicators, status callbacks, media uploads, or the contacts API beyond basic CRUD.
- Reach for [[sendblue-cli]] instead for shell-context outbound: one-shot scripts, cron jobs, agent hooks, "ping me when X" workflows.
- 当编写作为长期服务一部分、需要发送Sendblue消息的应用代码(服务器、工作进程、函数)时使用。
- 当通过Webhook接收入站消息时使用。
- 当需要CLI未提供的功能时使用:发送样式、消息反应、群组消息、输入状态提示、状态回调、媒体上传,或基础CRUD之外的联系人API功能。
- 若为Shell环境下的单次发送需求(如一次性脚本、定时任务、Agent钩子、"当X完成时通知我"工作流),请改用[[sendblue-cli]]。
How It Works
工作原理
Step 1: Authenticate
步骤1:身份验证
https://api.sendblue.comEvery request needs two headers:
sb-api-key-id: <YOUR_API_KEY_ID>
sb-api-secret-key: <YOUR_API_SECRET>
Content-Type: application/jsonKeep both values server-side — never ship them to a browser or mobile client.
https://api.sendblue.com每个请求都需要两个请求头:
sb-api-key-id: <YOUR_API_KEY_ID>
sb-api-secret-key: <YOUR_API_SECRET>
Content-Type: application/json请将这两个值保存在服务器端——绝不要将它们部署到浏览器或移动客户端。
Step 2: Send a message
步骤2:发送消息
bash
curl -X POST https://api.sendblue.com/api/send-message \
-H "sb-api-key-id: $KEY_ID" \
-H "sb-api-secret-key: $SECRET" \
-H 'Content-Type: application/json' \
-d '{
"number": "+15551234567",
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"content": "Hello from the API!"
}'Phone numbers must be E.164. must be a line you own — list yours with .
from_numberGET /api/linesbash
curl -X POST https://api.sendblue.com/api/send-message \
-H "sb-api-key-id: $KEY_ID" \
-H "sb-api-secret-key: $SECRET" \
-H 'Content-Type: application/json' \
-d '{
"number": "+15551234567",
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"content": "Hello from the API!"
}'电话号码必须采用E.164格式。必须是您拥有的号码——可通过列出您的所有号码。
from_numberGET /api/linesStep 3: Track delivery
步骤3:跟踪投递状态
The synchronous response includes a (Apple GUID — persist this; you need it for reactions and replies) and a from , , , , , , , . Only means it landed. Use instead of polling .
message_handlestatusREGISTEREDPENDINGQUEUEDACCEPTEDSENTDELIVEREDDECLINEDERRORDELIVEREDstatus_callback/api/status同步响应包含一个(苹果GUID——请保存该值,后续进行消息反应和回复时需要用到)以及一个状态值,可选状态包括、、、、、、、。只有表示消息已成功送达。请使用而非轮询接口。
message_handleREGISTEREDPENDINGQUEUEDACCEPTEDSENTDELIVEREDDECLINEDERRORDELIVEREDstatus_callback/api/statusStep 4: Receive inbound
步骤4:接收入站消息
Configure webhook URLs in the dashboard or via . Sendblue POSTs JSON to your endpoint. Respond with 2xx promptly — non-2xx triggers retries and duplicate deliveries. Event types: , , , , , , .
POST /api/account/webhooksreceiveoutboundtyping_indicatorcall_logline_blockedline_assignedcontact_created在控制面板中或通过配置Webhook URL。Sendblue会向您的端点发送POST请求并携带JSON数据。请及时返回2xx状态码——非2xx状态码会触发重试和重复投递。事件类型包括:、、、、、、。
POST /api/account/webhooksreceiveoutboundtyping_indicatorcall_logline_blockedline_assignedcontact_createdCore Endpoints
核心端点
| Method | Path | Purpose |
|---|---|---|
| POST | | Send a 1:1 message (text and/or media) |
| POST | | Send to multiple recipients |
| POST | | Create a named group thread |
| POST | | Send a tapback (love/like/dislike/laugh/emphasize/question) |
| POST | | Show "typing…" in the recipient's thread |
| POST | | Send a read receipt |
| POST | | Upload media (direct or from URL) |
| GET | | Poll a message's delivery status |
| GET | | Check whether a number is on iMessage |
| GET | | Read message history |
| GET / POST / PUT / DELETE | | Manage contacts |
| GET | | List your Sendblue phone numbers |
| POST | | CRUD webhook subscriptions |
| 请求方法 | 路径 | 用途 |
|---|---|---|
| POST | | 发送一对一消息(文本和/或媒体) |
| POST | | 向多个接收者发送消息 |
| POST | | 创建命名群组会话 |
| POST | | 发送Tapback反应(喜欢/点赞/踩/大笑/强调/疑问) |
| POST | | 在接收者的会话中显示"正在输入…" |
| POST | | 发送已读回执 |
| POST | | 上传媒体文件(直接上传或通过URL上传) |
| GET | | 轮询消息的投递状态 |
| GET | | 检查号码是否使用iMessage服务 |
| GET | | 查看消息历史 |
| GET / POST / PUT / DELETE | | 管理联系人 |
| GET | | 列出您的Sendblue电话号码 |
| POST | | 对Webhook订阅进行CRUD操作 |
Examples
示例
Example 1: Send with media, effects, and a status callback
示例1:发送带媒体、特效和状态回调的消息
json
POST /api/send-message
{
"number": "+15551234567",
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"content": "Optional text",
"media_url": "https://example.com/img.jpg",
"send_style": "celebration",
"status_callback": "https://yourapp.com/sendblue/status"
}contentmedia_urlsend_stylecelebrationshooting_starfireworkslasersloveconfettiballoonsspotlightechoinvisiblegentleloudslamjson
POST /api/send-message
{
"number": "+15551234567",
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"content": "Optional text",
"media_url": "https://example.com/img.jpg",
"send_style": "celebration",
"status_callback": "https://yourapp.com/sendblue/status"
}contentmedia_urlsend_stylecelebrationshooting_starfireworkslasersloveconfettiballoonsspotlightechoinvisiblegentleloudslamExample 2: Group message
示例2:群组消息
json
POST /api/send-group-message
{
"numbers": ["+15551234567", "+15557654321"],
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"content": "Hey team"
}The response returns a — persist it to send follow-ups into the same thread instead of creating a new one each time.
group_idjson
POST /api/send-group-message
{
"numbers": ["+15551234567", "+15557654321"],
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"content": "Hey team"
}响应会返回一个——请保存该值,以便后续发送消息到同一个会话,而非每次创建新会话。
group_idExample 3: React to a message
示例3:对消息做出反应
json
POST /api/send-reaction
{
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"message_handle": "<message_handle from prior send>",
"reaction": "love"
}Reactions only work on iMessage and need the original message's . Valid values: , , , , , .
message_handlelovelikedislikelaughemphasizequestionjson
POST /api/send-reaction
{
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"message_handle": "<message_handle from prior send>",
"reaction": "love"
}消息反应仅适用于iMessage,且需要原始消息的。有效值包括:、、、、、。
message_handlelovelikedislikelaughemphasizequestionExample 4: Inbound webhook payload (receive
)
receive示例4:入站Webhook负载(receive
事件)
receivejson
{
"accountEmail": "you@example.com",
"content": "Reply text",
"media_url": "https://...",
"is_outbound": false,
"number": "+15551234567",
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"service": "iMessage",
"group_id": "...",
"date_sent": "2024-01-01T12:00:00Z"
}Status callback payloads () mirror the send-message response and update as the message moves through → (or ).
outboundSENTDELIVEREDERRORjson
{
"accountEmail": "you@example.com",
"content": "Reply text",
"media_url": "https://...",
"is_outbound": false,
"number": "+15551234567",
"from_number": "+1YOUR_SENDBLUE_NUMBER",
"service": "iMessage",
"group_id": "...",
"date_sent": "2024-01-01T12:00:00Z"
}状态回调负载(事件)与发送消息的响应结构一致,会随着消息状态从变为(或)而更新。
outboundSENTDELIVEREDERRORBest Practices
最佳实践
- ✅ Persist on every send. You need it for reactions, replies, and correlating status callbacks.
message_handle - ✅ Use over polling. It's lower-cost and more accurate than
status_callback.GET /api/status - ✅ Return 2xx fast from your webhook, then process async. Non-2xx triggers duplicate deliveries.
- ✅ Check service with before relying on iMessage-only features for a recipient.
/api/evaluate-service - ✅ Rehost inbound media on receipt — media URLs expire in ~30 days.
- ❌ Don't ship /
sb-api-key-idto a client. They are server-side credentials.sb-api-secret-key - ❌ Don't treat a 200 on as delivery. It only means "accepted".
/api/send-message
- ✅ 每次发送消息后保存。后续进行消息反应、回复以及关联状态回调时需要用到它。
message_handle - ✅ 使用而非轮询。相比
status_callback,它的成本更低且更准确。GET /api/status - ✅ 从Webhook快速返回2xx状态码,然后异步处理请求。非2xx状态码会触发重复投递。
- ✅ 在依赖iMessage专属功能前,使用检查服务状态。
/api/evaluate-service - ✅ 接收入站媒体后重新托管——媒体URL会在约30天后过期。
- ❌ 不要将/
sb-api-key-id部署到客户端。它们是服务器端凭据。sb-api-secret-key - ❌ 不要将返回的200状态码视为消息已投递。它仅表示"已接受"。
/api/send-message
Limitations
限制
- Synchronous send responses only report acceptance, not delivery. Final state arrives via or
status_callback.GET /api/status - silently no-ops on SMS (green-bubble recipients).
send_style - Inbound media URLs expire in ~30 days.
- Per-line rate limits apply; bursting many sends from one number can trip Apple's spam heuristics — pace them or split across lines.
- Reactions and effects are iMessage-only.
- 同步发送响应仅报告消息是否被接受,不报告投递状态。最终状态需通过或
status_callback获取。GET /api/status - 在SMS消息中会静默失效(接收者为绿色气泡消息)。
send_style - 入站媒体URL会在约30天后过期。
- 每个号码都有速率限制;从单个号码批量发送大量消息可能会触发苹果的垃圾邮件检测机制——请控制发送频率或分散到多个号码发送。
- 消息反应和特效仅适用于iMessage。
Security & Safety Notes
安全与注意事项
- Keep and
sb-api-key-idserver-side. They are not safe in browser, mobile, or CI logs.sb-api-secret-key - Webhook endpoints should be on HTTPS and idempotent — same may arrive more than once.
message_handle - Sensitive data in message content is visible in lock-screen previews on the recipient's device. Don't embed secrets, tokens, or full PII — link to an authenticated dashboard or shortened payload instead.
- Rotate API keys from the Sendblue dashboard if either value is exposed; the old pair is invalidated on rotation.
- 请将和
sb-api-key-id保存在服务器端。它们在浏览器、移动客户端或CI日志中是不安全的。sb-api-secret-key - Webhook端点应使用HTTPS且具备幂等性——同一个可能会多次到达。
message_handle - 消息内容中的敏感数据会在接收者设备的锁屏预览中显示。请勿嵌入密钥、令牌或完整的个人身份信息——应链接到经过身份验证的控制面板或简化的负载内容。
- 如果任一凭据泄露,请在Sendblue控制面板中轮换API密钥;旧密钥对在轮换后会失效。
Common Pitfalls
常见陷阱
- E.164 only. or
5551234567will fail — always send(555) 123-4567.+15551234567 - must be one of your lines. A spoofed or unprovisioned number returns an error.
from_number - silently no-ops on SMS. If the recipient is green-bubble, effects don't render — check service first with
send_styleif it matters./api/evaluate-service - Store . You need it for reactions, replies, and correlating status callbacks back to your records.
message_handle - Media URLs expire in ~30 days. If you need durable media from inbound webhooks, download and re-host on receipt.
- Status is async. A 200 on means accepted, not delivered. Use
/api/send-messagerather than blocking on the synchronous response.status_callback - Webhook retries on non-2xx. Return 200 even when you've decided to ignore the event; otherwise expect duplicate deliveries.
- Rate limits apply per line. Bursting many sends from one number trips Apple's spam heuristics — pace them or split across lines.
- 仅支持E.164格式。或
5551234567会请求失败——务必发送(555) 123-4567格式的号码。+15551234567 - 必须是您的号码之一。伪造或未配置的号码会返回错误。
from_number - 在SMS中静默失效。如果接收者使用绿色气泡消息,特效不会显示——如果对此有要求,请先使用
send_style检查服务状态。/api/evaluate-service - 保存。后续进行消息反应、回复以及关联状态回调到您的记录时需要用到它。
message_handle - 媒体URL约30天后过期。如果需要长期保存入站Webhook中的媒体,请在接收时下载并重新托管。
- 状态是异步的。返回200仅表示消息已被接受,不代表已投递。请使用
/api/send-message而非等待同步响应。status_callback - 非2xx状态码会触发Webhook重试。即使您决定忽略该事件,也请返回200状态码;否则会收到重复投递。
- 每个号码都有速率限制。从单个号码批量发送大量消息会触发苹果的垃圾邮件检测机制——请控制发送频率或分散到多个号码发送。
Related Skills
相关技能
- — Shell wrapper for shell-context outbound (scripts, cron, agent hooks). Use it when you don't need a full HTTP integration.
@sendblue-cli - — Patterns and copy rules for outbound "text me when X is done" notifications layered on top of the API or CLI.
@sendblue-notify
- —— 适用于Shell环境下的消息发送(脚本、定时任务、Agent钩子)的Shell包装器。当您不需要完整的HTTP集成时使用它。
@sendblue-cli - —— 基于API或CLI构建的出站"当X完成时通知我"消息的模式和复制规则。
@sendblue-notify
Links
链接
- Full reference: https://docs.sendblue.com/
- Sendblue: https://sendblue.com
- Useful undocumented-here features: carousels (), FaceTime/contact-card sharing, advanced webhook filtering, contacts API beyond basic CRUD — see the docs site.
/api/send-carousel
- 完整参考文档:https://docs.sendblue.com/
- Sendblue官网:https://sendblue.com
- 本文档未提及的实用功能:轮播消息()、FaceTime/联系人卡片分享、高级Webhook过滤、基础CRUD之外的联系人API功能——请查看官方文档网站。
/api/send-carousel