DEVELOPER API
SMS API 一條金鑰即可發送
透過 SMSOnline 從你的 App、網店或預約系統發送短訊。價格及規則與網頁發送畫面相同。
20,000每次請求號碼數
120每分鐘請求數
JSON輸入及輸出
QUICK START
開始使用
- 01在帳戶的 API 頁面建立金鑰(以 so_ 開頭)。
- 02每次請求都加上 Authorization: Bearer <key> 標頭。
- 03先以 POST /api/v1/quote 查看費用,再以 POST /api/v1/messages 發送。
Base URL
https://smsonline.blog/api/v1
ENDPOINTS
端點
| 請求 | 用途 |
|---|---|
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 | 在發送前取消預約,全數退款 |
SEND
發送
to 為號碼陣列或以換行分隔的文字。如要使用沒有 + 號的號碼,請將 country 設為預設國家代碼(例如 us 或 kr)。
| 欄位 | 說明 |
|---|---|
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.012",
"countries": [
{ "country": "US", "recipients": 1, "cost": "0.0047" },
{ "country": "GB", "recipients": 1, "cost": "0.0073" }
]
},
"rejected": [],
"duplicates": 0,
"opted_out": 0,
"balance": "48.988"
}POST /api/v1/messages
curl -X POST https://smsonline.blog/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://smsonline.blog/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.0147",
"balance": "49.00",
"countries": [
{ "country": "JP", "recipients": 1, "price": "0.01", "cost": "0.01" },
{ "country": "US", "recipients": 1, "price": "0.0047", "cost": "0.0047" }
],
"rejected": [],
"duplicates": 0,
"opted_out": 0
}ERRORS
錯誤代碼
| 代碼 | 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 | 預約時間超出範圍 |
low_balance | 402 | 餘額不足 |
unavailable | 503 | 暫未開放發送(不會收費) |
not_found | 404 | 找不到此發送 |
not_scheduled | 409 | 已發送或已取消 |