發送
使用 POST /v1/batches 發送群發簡訊
/v1/batches在一個請求中發送至最多 10,000 個號碼。整個費用會一次性從餘額中扣除。
請求主體
- toarray of strings選填
用於一條共享簡訊的號碼。使用 to 與 text,或 messages。
- textstring選填
共享簡訊,與 to 一起使用時為必填。
- messagesarray of objects選填
每個收件人一個 {to, text},用於個人化簡訊。
- namestring選填
控制台的標籤,最多 100 個字元。
- referencestring選填
您自己的 id,最多 100 個字元,會在批次和每條訊息中返回。
- send_atstring選填
ISO 8601 時間,2 分鐘到 45 天後。
curl https://bulksmsapi.cc/v1/batches \
-H "Authorization: Bearer $BULKSMSAPI_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: spring-sale-0412" \
-d '{
"name": "Spring sale",
"text": "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
"to": [
"+14155550123",
"+447400123456",
"+4915123456789"
]
}'const res = await fetch("https://bulksmsapi.cc/v1/batches", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.BULKSMSAPI_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "spring-sale-0412",
},
body: JSON.stringify({
name: "Spring sale",
text: "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
to: ["+14155550123", "+447400123456", "+4915123456789"],
}),
});
const batch = await res.json();
console.log(res.status, batch.id, batch.recipients, batch.cost);import json, os, urllib.request
req = urllib.request.Request(
"https://bulksmsapi.cc/v1/batches",
data=json.dumps({
"name": "Spring sale",
"text": "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
"to": ["+14155550123", "+447400123456", "+4915123456789"],
}).encode(),
headers={
"Authorization": "Bearer " + os.environ["BULKSMSAPI_KEY"],
"Content-Type": "application/json",
"Idempotency-Key": "spring-sale-0412",
"User-Agent": "northwind-app/1.0",
},
method="POST",
)
with urllib.request.urlopen(req) as res:
batch = json.load(res)
print(res.status, batch["id"], batch["recipients"], batch["cost"])<?php
$ch = curl_init("https://bulksmsapi.cc/v1/batches");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("BULKSMSAPI_KEY"),
"Content-Type: application/json",
"Idempotency-Key: spring-sale-0412",
],
CURLOPT_POSTFIELDS => json_encode([
"name" => "Spring sale",
"text" => "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
"to" => ["+14155550123", "+447400123456", "+4915123456789"],
]),
]);
$batch = json_decode(curl_exec($ch), true);
echo $batch["id"], " ", $batch["recipients"], " ", $batch["cost"], "\n";package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
body, _ := json.Marshal(map[string]any{
"name": "Spring sale",
"text": "Spring sale at Northwind: 20% off until Sunday. Opt out: northwind.example/sms",
"to": []string{"+14155550123", "+447400123456", "+4915123456789"},
})
req, _ := http.NewRequest("POST", "https://bulksmsapi.cc/v1/batches", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+os.Getenv("BULKSMSAPI_KEY"))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", "spring-sale-0412")
res, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
var batch map[string]any
json.NewDecoder(res.Body).Decode(&batch)
fmt.Println(res.StatusCode, batch["id"], batch["recipients"], batch["cost"])
}{
"id": "bat_6TQ2W8M1ZK4N",
"object": "batch",
"name": "Spring sale",
"status": "queued",
"source": "api",
"encoding": "GSM-7",
"recipients": 3,
"max_segments": 1,
"cost": "0.02741",
"refunded": "0.00000",
"currency": "USD",
"counts": { "scheduled": 0, "queued": 3, "sent": 0, "delivered": 0, "failed": 0, "canceled": 0 },
"send_at": null,
"reference": null,
"created_at": "2026-11-07T09:31:40.102Z",
"completed_at": null,
"set_aside": []
}保留的號碼
每個號碼都會獨立進行清理和計價。無法發送的號碼會被排除在批次之外,不會收費,並在 set_aside 中列出原因:
| reason | 含義 |
|---|---|
| invalid_number | 清理後無法讀取為 + 和 7 到 15 位數字。 |
| duplicate | 同一個號碼在請求中先前出現過。 |
| unsupported_country | 該號碼不屬於計價國家。 |
| too_long | 其個人化簡訊需要超過 10 個分段。 |
| empty_text | 其個人化簡訊為空。 |
| suppressed | 該號碼在您的發送排除清單中。 |
如果沒有剩餘號碼,請求會失敗並返回第一個原因的代碼(例如 invalid_number),且不會收取任何費用。
每個號碼的個人化簡訊
使用 messages 為每個收件人提供其個人化簡訊:姓名、時間、金額。每條簡訊都會獨立計數和計價,因此批次可以混合單分段和雙分段訊息。
curl https://bulksmsapi.cc/v1/batches \
-H "Authorization: Bearer $BULKSMSAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Appointment reminders, 14 May",
"send_at": "2026-05-13T16:00:00Z",
"messages": [
{ "to": "+14155550123", "text": "Hi Ana, your dental check-up is tomorrow at 09:30." },
{ "to": "+14155550178", "text": "Hi Sam, your dental check-up is tomorrow at 11:00." }
]
}'Scheduling
使用 send_at 時,批次及其訊息會處於 scheduled 狀態,並在該分鐘移動到佇列。費用會在請求被接受時扣除,因此排程批次始終有足夠的資金。排程批次在開始前可以取消。
/v1/batches/{id}/cancel取消排程批次:每條訊息都會被取消,且全額費用會作為一條退款記錄返還到餘額。已開始的批次會返回 409 not_cancelable。
curl -X POST https://bulksmsapi.cc/v1/batches/bat_6TQ2W8M1ZK4N/cancel \
-H "Authorization: Bearer $BULKSMSAPI_KEY"檢索和列出批次
/v1/batches/{id}批次及其各狀態的即時計數。輪詢它以獲取進度,或使用 webhooks。
/v1/batches帳戶的批次,最新優先,限制(1 到 100)和 starting_after(bat_ id)。
批次欄位
- idstring
bat_ 後接 12 個字元。
- statusstring
scheduled(已排程)、queued(排隊中)、sending(發送中)、completed(已完成)或 canceled(已取消)。
- sourcestring
api 或 console。
- encodingstring
GSM-7,或當任何文字需要 Unicode 時使用 UCS-2。
- recipientsinteger
批次中接受的號碼。
- max_segmentsinteger
文字中最大的分段數。
- coststring
從餘額中扣除的總金額,美元。
- refundedstring
目前為止因失敗或取消的訊息所退回的總金額。
- countsobject
每個狀態的訊息數:scheduled(已排程)、queued(排隊中)、sent(已發送)、delivered(已送達)、failed(失敗)、canceled(已取消)。
- send_atstring or null
排程時間(如有)。
- completed_atstring or null
當最後一則訊息達到最終狀態時。
較大的列表
將超過 10,000 個號碼的列表拆分為多個請求,每個請求都有自己的 Idempotency-Key(例如列表 ID 和部分編號)。訊息按順序以每分鐘最多 1,200 則的速度遞交給網路,因此一個 50,000 個號碼的活動將在一小時內完成。控制台從貼上或 CSV 文件中每場活動最多接受 50,000 個號碼。