快速開始
- 在控制台創建帳戶並為您的餘額充值。
- 打開 API 密鑰 並創建一個密鑰。首次充值後即可創建密鑰。密鑰僅顯示一次;請將其存儲為秘密。
- 向
/sms發送 POST 請求,包含號碼和文本。讀取返回的推廣活動 ID,然後在控制台或通過網頁掛鉤跟蹤送達情況。
身份驗證
除公開費率列表外,每個請求都需在 Authorization 標頭中攜帶您的密鑰。密鑰以 sbk_live_ 開頭。新密鑰會立即替換舊密鑰。
Authorization: Bearer sbk_live_YOUR_KEY發送短訊
POST/sms
創建推廣活動,從餘額中扣除費用並將每條短訊排隊。號碼會被清理和去重;無法使用的號碼將在 dropped 中返回原因且不會收費。
| 字段 | 類型 | 描述 |
|---|---|---|
to必填 | 字符串或數組 | 一個號碼或最多 10,000 個號碼的陣列,國際格式,例如 "+447700900461" |
text必填 | 字符串 | 短訊文本,最多 10 段。GSM-7 文本每段 160 個字符,UCS-2 每段 70 個字符 |
schedule_at可選 | 字符串 | ISO 8601 時間,從 5 分鐘到 60 天後。省略則立即發送 |
client_ref可選 | 字符串 | 您自己的參考,最多 64 個 a-z A-Z 0-9 _ . :, 字符,在報告和網頁掛鉤中返回 |
opt_out可選 | 布爾值 | true 會附加您在帳戶設置中設置的退訂行 |
curl -X POST https://sendbulksms.cc/api/v1/sms \
-H "Authorization: Bearer sbk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": ["+447700900461", "+5511955550123"],
"text": "Hi, your order 4821 ships today.",
"client_ref": "orders-4821"
}'const res = await fetch("https://sendbulksms.cc/api/v1/sms", {
method: "POST",
headers: { Authorization: "Bearer " + process.env.SENDBULKSMS_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ to: ["+447700900461", "+5511955550123"], text: "Hi, your order 4821 ships today.", client_ref: "orders-4821" }),
});
const campaign = await res.json();
console.log(res.status, campaign.id, campaign.cost);import os, requests
r = requests.post(
"https://sendbulksms.cc/api/v1/sms",
headers={"Authorization": "Bearer " + os.environ["SENDBULKSMS_KEY"]},
json={"to": ["+447700900461", "+5511955550123"], "text": "Hi, your order 4821 ships today.", "client_ref": "orders-4821"},
timeout=30,
)
print(r.status_code, r.json()["id"])<?php
$ch = curl_init("https://sendbulksms.cc/api/v1/sms");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . getenv("SENDBULKSMS_KEY"), "Content-Type: application/json"],
CURLOPT_POSTFIELDS => json_encode(["to" => ["+447700900461", "+5511955550123"], "text" => "Hi, your order 4821 ships today.", "client_ref" => "orders-4821"]),
]);
$campaign = json_decode(curl_exec($ch), true);
echo $campaign["id"];回應:推廣活動及其費用和前 1,000 條短訊。 使用推廣活動短訊獲取更多。
HTTP/1.1 201 Created
{
"id": "CP-7KQ2-M9XA-4HTD",
"status": "sending",
"source": "api",
"recipients": 2,
"segments": 1,
"encoding": "GSM-7",
"cost": "0.01078",
"refunded": "0.00000",
"client_ref": "orders-4821",
"scheduled_at": null,
"created_at": "2026-11-07T10:32:04.118Z",
"done_at": null,
"counts": { "queued": 2, "sent": 0, "delivered": 0, "failed": 0, "canceled": 0 },
"dropped": [],
"balance": "248.30422",
"messages": [
{ "id": "SM-2RBW-8MZN-QF6K", "campaign_id": "CP-7KQ2-M9XA-4HTD", "to": "+447700900461", "country": "GB", "parts": 1, "price": "0.00819", "status": "queued", "error": null, "created_at": "2026-11-07T10:32:04.118Z", "sent_at": null, "done_at": null }
]
}估算發送
POST/estimate
接受與 /sms 相同的主體,並返回收件人、段數、編碼、總費用和每個國家的費用,但不收費或發送任何內容。
{ "recipients": 2, "dropped": [], "segments": 1, "encoding": "GSM-7", "cost": "0.01078", "balance": "248.31500",
"countries": [ { "country": "GB", "recipients": 1, "cost": "0.00819" }, { "country": "BR", "recipients": 1, "cost": "0.00259" } ] }短訊狀態
GET/sms/{message_id}
返回一條短訊:號碼、國家、段數、價格、狀態、失敗短訊的錯誤以及每個步驟的時間。
推廣活動
GET/campaigns/{campaign_id}
推廣活動及其費用、退款和每種狀態的短訊計數。
GET/campaigns/{campaign_id}/messages?offset=0&limit=100
按排隊順序的短訊,每頁最多 1,000 條。
POST/campaigns/{campaign_id}/cancel
取消尚未開始的預定推廣活動,並將其全額費用退還至餘額。
餘額及費率
GET/balance
{ "balance": "248.31500", "currency": "USD" }GET/rates
公開,無需密鑰。每個國家及其電話號碼和每段費用。/rates/GB 返回一個國家。
{ "updated": "2026-11-07", "rates": [ { "country": "GB", "name": "United Kingdom", "calling_code": "+44", "price": "0.00819", "currency": "USD", "unit": "SMS segment" } ] }送達網頁掛鉤
在控制台的 API 密鑰下設置網頁掛鉤 URL。當短訊達到最終狀態(送達或失敗)時,我們會將報告 POST 到該 URL。在 8 秒內以任何 2xx 狀態回應;否則將在約 11 小時內重試最多 8 次。使用 id 忽略您已處理的報告。
POST https://your-server.example/sms-status
Content-Type: application/json
X-SendBulkSMS-Signature: t=1794047524,v1=5f0c3b9e...
{
"event": "message.status",
"id": "evt_8c1d2e4f6a7b9c0d1e2f",
"created_at": "2026-11-07T10:32:09.004Z",
"data": {
"message_id": "SM-2RBW-8MZN-QF6K",
"campaign_id": "CP-7KQ2-M9XA-4HTD",
"to": "+447700900461",
"country": "GB",
"status": "delivered",
"error": null,
"parts": 1,
"price": "0.00819",
"client_ref": "orders-4821",
"done_at": "2026-11-07T10:32:08.912Z"
}
}在信任報告之前檢查簽名:使用您的網頁掛鉤秘密對 t + "." + raw body 進行 HMAC-SHA256 計算,並在恆定時間內進行比較,拒絕超過 5 分鐘的時間。
import { createHmac, timingSafeEqual } from "node:crypto";
// raw = the request body exactly as received (string), header = X-SendBulkSMS-Signature
export function verify(raw, header, secret) {
const m = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(header || "");
if (!m || Math.abs(Date.now() / 1000 - Number(m[1])) > 300) return false;
const want = Buffer.from(createHmac("sha256", secret).update(m[1] + "." + raw).digest("hex"));
const got = Buffer.from(m[2]);
return want.length === got.length && timingSafeEqual(want, got);
}import hmac, hashlib, re, time
def verify(raw: bytes, header: str, secret: str) -> bool:
m = re.fullmatch(r"t=(\d+),v1=([0-9a-f]{64})", header or "")
if not m or abs(time.time() - int(m.group(1))) > 300:
return False
want = hmac.new(secret.encode(), m.group(1).encode() + b"." + raw, hashlib.sha256).hexdigest()
return hmac.compare_digest(want, m.group(2))<?php
function verify(string $raw, string $header, string $secret): bool {
if (!preg_match('/^t=(\d+),v1=([0-9a-f]{64})$/', $header, $m) || abs(time() - (int)$m[1]) > 300) return false;
$want = hash_hmac('sha256', $m[1] . '.' . $raw, $secret);
return hash_equals($want, $m[2]);
}狀態
| 狀態 | 含義 |
|---|---|
queued | 已接受並扣費,正在排隊等候處理 |
sent | 已交給路由,等待送達報告 |
delivered | 網絡已確認送達至手機 |
failed | 未送達;費用已退還,錯誤信息包含原因 |
canceled | 已取消的預定活動的一部分;費用已退還 |
錯誤
錯誤使用HTTP狀態碼和JSON主體:{ "error": { "code": "insufficient_balance", "message": "..." } }。返回錯誤的請求不會扣除餘額。
| HTTP | 代碼 | 何時 |
|---|---|---|
| 400 | bad_request缺少或無效的字段;消息會解釋是哪一個 | 缺少或無效的字段;消息會解釋是哪一個 |
| 400 | no_valid_numbers"to"中的號碼均無法使用 | "to"中的號碼均無法使用 |
| 401 | unauthorizedAPI密鑰缺失或無效 | API密鑰缺失或無效 |
| 402 | insufficient_balance餘額不足以支付發送費用;未扣除任何費用 | 餘額不足以支付發送費用;未扣除任何費用 |
| 404 | not_found活動、消息或端點在您的帳戶中不存在 | 活動、消息或端點在您的帳戶中不存在 |
| 409 | not_scheduled只有尚未開始的預定活動才能取消 | 只有尚未開始的預定活動才能取消 |
| 413 | too_many_recipients一個請求中超過10,000個號碼 | 一個請求中超過10,000個號碼 |
| 429 | rate_limited一分鐘內此密鑰超過300個請求 | 一分鐘內此密鑰超過300個請求 |
| 500 | server_error請重試;失敗的請求不會扣除費用 | 請重試;失敗的請求不會扣除費用 |
限制
- 每個API密鑰每分鐘300個請求。
- 每個發送請求10,000個號碼;每條消息10個分段。
- 消息按接受順序每分鐘最多200條離開隊列。
- 預定時間從5分鐘到60天前。
- 您的禁止發送列表中的號碼將被跳過並以代碼suppressed返回在dropped中;不會扣除費用。