Developers · REST API

透過 REST API 串接發送 SMS 與 OTP

直接從你的系統發送訊息,送達所有泰國電信網路,使用單一 API Key 進行驗證。註冊前可先在此了解詳情。

Base URL https://sepsms.com/api/v2
Quick start

3 個步驟開始串接

1

取得 API Key

註冊並在開發者儀表板建立金鑰。金鑰採 sk_sep_ 格式,僅在建立時顯示一次。

2

附上 Header

在每個請求中透過 X-API-Key header 帶上金鑰,可逐一設定權限(scope)並限制每組金鑰的 IP。

3

呼叫 Endpoint

以 JSON 格式向 Base URL 發送請求,所有回應皆為 JSON。

POST/message/send
curl -X POST https://sepsms.com/api/v2/message/send \
  -H "X-API-Key: sk_sep_..." \
  -H "Content-Type: application/json" \
  -d '{
    "origin": "SEPSMS",
    "recipients": ["66812345678", "66898765432"],
    "message": "สวัสดีคุณลูกค้า รับส่วนลด 10% วันนี้",
    "scheduledTime": null
  }'
Authentication

使用 API Key 驗證

每個請求皆以 X-API-Key header 帶上你的 sk_sep_ 金鑰。每組金鑰可設定專屬任務的權限(scope)、限制 IP,並各自設定每分鐘的限制。

Header
X-API-Key: sk_sep_3f9a...d21c
可逐組金鑰指派的權限(scopes)
  • sms:send發送 / 定時 / 取消 SMS
  • sms:read讀取歷史與送達狀態
  • otp:send發送 OTP 驗證碼
  • otp:verify驗證 OTP 驗證碼
  • credit:read讀取剩餘點數餘額
  • webhooks:read / write管理通知 webhook
Reference

主要 Endpoints

串接時最常使用的 endpoint

POST /message/send sms:send

發送 SMS

在單一請求中發送訊息給一個或多個目標號碼,可加入個別收件人的變數(personalize),或預先設定發送時間。

originstring已核准的寄件人名稱(Sender Name)
messagestring要發送的訊息內容
recipientsstring[]目標號碼,格式為 0xxxxxxxxx 或 66xxxxxxxxx
scheduledTimestring?ISO 8601 格式的發送時間(留空 = 立即發送)
variablesobject?用於個人化的個別收件人變數值
請求
curl -X POST https://sepsms.com/api/v2/message/send \
  -H "X-API-Key: sk_sep_..." \
  -H "Content-Type: application/json" \
  -d '{
    "origin": "SEPSMS",
    "recipients": ["66812345678", "66898765432"],
    "message": "สวัสดีคุณลูกค้า รับส่วนลด 10% วันนี้",
    "scheduledTime": null
  }'
回應
{
  "result": {
    "uuid": "9f8b2c1e-...",
    "refNo": "SP240115...",
    "totalMsisdn": 2,
    "totalCredit": 2,
    "blockedCount": 0,
    "status": "pending"
  }
}
POST /otp/send otp:send

發送 OTP

發送一次性驗證碼並附上參考碼(reference),系統會產生驗證碼並透過 SMS 發送,驗證碼本身不會在回應中傳回。

destinationstring目標號碼
originstring寄件人名稱
templatestring?訊息內容,必須包含 {code}(也可加入 {ref})
ttlSecondsnumber?驗證碼有效時間 60-600 秒(預設 300)
codeLengthnumber?驗證碼長度 4-8 位數
請求
curl -X POST https://sepsms.com/api/v2/otp/send \
  -H "X-API-Key: sk_sep_..." \
  -H "Content-Type: application/json" \
  -d '{
    "destination": "66812345678",
    "origin": "SEPSMS",
    "template": "รหัสยืนยันของคุณคือ {code} (Ref: {ref})"
  }'
回應
{
  "result": {
    "uuid": "1a2b...",
    "reference": "A3K9X2",
    "destination": "66812345678",
    "expiresAt": "2026-01-15T10:35:00.000Z",
    "ttlSeconds": 300
  }
}
POST /otp/verify otp:verify

驗證 OTP

依據發送時取得的 reference,驗證使用者輸入的驗證碼。

referencestring發送 OTP 時取得的參考碼
pinstring使用者輸入的驗證碼
請求
curl -X POST https://sepsms.com/api/v2/otp/verify \
  -H "X-API-Key: sk_sep_..." \
  -H "Content-Type: application/json" \
  -d '{ "reference": "A3K9X2", "pin": "123456" }'
回應
{ "result": { "reference": "A3K9X2", "verified": true } }
GET /message/{uuid} sms:read

送達狀態

查看已發送訊息的送達狀態彙整(依號碼的明細請見 /message/{uuid}/recipients)。

uuidpath發送 SMS 時取得的 uuid
請求
curl https://sepsms.com/api/v2/message/9f8b2c1e-... \
  -H "X-API-Key: sk_sep_..."
回應
{
  "result": {
    "uuid": "9f8b2c1e-...",
    "origin": "SEPSMS",
    "status": "completed",
    "totalMsisdn": 2,
    "drSummary": [
      { "drStatus": "success", "count": 2 }
    ],
    "refundedCount": 0
  }
}
GET /message/credit/balance credit:read

剩餘點數餘額

查詢帳號中的剩餘點數餘額

請求
curl https://sepsms.com/api/v2/message/credit/balance \
  -H "X-API-Key: sk_sep_..."
回應
{ "result": { "balance": 18420 } }
POST /webhooks webhooks:write

Webhook 通知

從開發者儀表板註冊與管理你的端點 URL(需登入,無法透過 API Key 建立)。註冊後,每個事件(例如發送成功/失敗、送達結果、點數即將用盡)都會 POST 到你的 URL。每個 payload 皆以 HMAC-SHA256 簽署(X-Webhook-Signature header)。

urlstring用於接收 event 的 HTTPS 端點
eventsstring[]你想接收的 event 清單
請求
# Webhook endpoints are registered + managed in the
# developer dashboard (logged-in). Registration is not
# available to API keys. Registration payload:
{
  "url": "https://your-app.com/hooks/sepsms",
  "events": ["dr.success", "dr.failed"]
}
回應
// POST sent to your URL. The event name, timestamp and
// signature travel in headers, not the body:
//   X-Webhook-Event: dr.success
//   X-Webhook-Timestamp: 1737020405
//   X-Webhook-Signature: t=1737020405,v1=<hmac-sha256>
{
  "smsUuid": "9f8b2c1e-...",
  "msisdn": "66812345678",
  "txId": "8f3a1c9d...",
  "status": "success"
}

Webhook events: sms.sentsms.failedsms.completeddr.successdr.failedotp.verifiedcredit.loworder.completed

Rate limits

呼叫限制

超過限制會回傳 429 狀態,並附上 RateLimit-Remaining 與 Retry-After header

發送 SMS120 次 / 分鐘
發送 OTP5 次 / 分鐘 / IP
所有 endpoint 合計2,400 次 / 分鐘
Errors

錯誤格式

所有類型的錯誤皆以相同結構回應,可讀取 error.code 在程式中處理。

例如 401 Unauthorized
{
  "success": false,
  "error": {
    "code": "auth.invalid_credentials",
    "message": "API key is missing or invalid"
  }
}

準備好串接了嗎?

免費註冊並立即建立 API Key,今天就開始從你的系統發送訊息。

仍在使用舊系統(sep2p)嗎?位於 /api/sms 與 /api/otp 的 v1 endpoint 仍支援以 Bearer token 進行的舊版串接。