給開發者
短訊 API 以 REST 發送短訊群發及驗證碼
把您的應用程式、網店或預約系統接駁到 WorldText 短訊平台。價格和發送規則與網頁發送介面相同。
20,000每個請求最多號碼數
120每個金鑰每分鐘請求數
JSON請求及回應
快速開始
第一個請求
- 01進入帳戶的 API 頁面並產生金鑰。金鑰以 wt_ 開頭。
- 02在每個請求加上標頭 Authorization: Bearer <金鑰>。
- 03先用 POST /api/v1/quote 取得報價,再經 POST /api/v1/messages 發送。
基本網址
https://worldtext.world/api/v1
端點
端點列表
| 方法及路徑 | 用途 |
|---|---|
GET /api/v1/balance | 目前餘額,以美元計 |
GET /api/v1/countries | 覆蓋國家及每條價格(毋須金鑰) |
POST /api/v1/quote | 價格、條數及被過濾的號碼,不會發送 |
POST /api/v1/messages | 立即發送,設定 schedule_at 時則稍後發送 |
GET /api/v1/messages | 最近發送列表(limit、offset) |
GET /api/v1/messages/{id} | 單次發送及各國結果 |
POST /api/v1/messages/{id}/cancel | 取消未發出的預約發送並全數退款 |
發送
發送短訊
to 欄位可傳入號碼陣列,或每行一個號碼的文字。號碼沒有 + 時,請把 country 欄位設為兩個字母的國家代碼,例如 hk 或 us。
| 欄位 | 說明 |
|---|---|
to | 收件人。陣列,或每行一個號碼,最多 20,000 個 |
text | 短訊內容,不超過 10 條 |
country | 選填。沒有 + 的號碼所用的兩個字母國家代碼 |
schedule_at | 選填。包含時區的 ISO 時間(例如 2026-12-01T09:00:00Z)或 Unix 秒數,須在 5 分鐘至 30 日後之間 |
client_ref | 選填。您自己的參考編號,最多 64 個字元 |
回應 · 201201 Created
{
"ok": true,
"campaign": {
"id": "K7Q2M9XD4TPA",
"status": "sending",
"recipients": 2,
"parts": 1,
"encoding": "GSM-7",
"cost": "0.0105",
"countries": [
{ "country": "US", "recipients": 1, "cost": "0.0041" },
{ "country": "GB", "recipients": 1, "cost": "0.0064" }
]
},
"rejected": [],
"duplicates": 0,
"opted_out": 0,
"balance": "48.9895"
}POST /api/v1/messages
curl -X POST https://worldtext.world/api/v1/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": ["+14155550142", "+447400123456"],
"text": "Your order #A2847 has shipped."
}'POST /api/v1/quote
curl -X POST https://worldtext.world/api/v1/quote \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "to": ["+14155550142", "+819012345678"], "text": "Hello" }'回應 · 200200 OK
{
"ok": true,
"recipients": 2,
"parts": 1,
"encoding": "GSM-7",
"cost": "0.0131",
"balance": "49.00",
"countries": [
{ "country": "JP", "recipients": 1, "price": "0.009", "cost": "0.009" },
{ "country": "US", "recipients": 1, "price": "0.0041", "cost": "0.0041" }
],
"rejected": [],
"duplicates": 0,
"opted_out": 0
}錯誤
錯誤回應
| 代碼 | HTTP | 原因 |
|---|---|---|
unauthorized | 401 | 沒有金鑰,或金鑰無效 |
rate_limited | 429 | 這一分鐘內請求太多 |
bad_request | 400 | 無法解析請求內容 |
empty_text | 400 | 沒有短訊內容 |
too_long | 400 | 內容超過 10 條 |
no_numbers | 400 | 沒有可發送的號碼 |
too_many | 400 | 一個請求超過 20,000 個號碼 |
bad_time | 400 | schedule_at 不在允許範圍內 |
low_balance | 402 | 餘額不足以完成這次發送 |
unavailable | 503 | 目前暫停發送,沒有扣除餘額 |
not_found | 404 | 該發送 id 不存在 |
not_scheduled | 409 | 該次發送已發出或已取消 |