เริ่มต้นอย่างรวดเร็ว
- 1. สร้างคีย์ ในพื้นที่ทำงาน เปิด API และ webhooks คีย์จะเปิดใช้งานหลังจากเติมเงินครั้งแรก; แต่ละคีย์จะแสดงเพียงครั้งเดียว ดังนั้นให้คัดลอกหรือบันทึกเป็นไฟล์ข้อความ
- 2. ตรวจสอบค่าใช้จ่าย POST เนื้อหาเดียวกันไปยัง
/costsเพื่อดูผู้รับ ส่วนข้อความ และยอดรวมโดยไม่ต้องส่ง - 3. ส่ง POST ไปยัง
/sendsคำตอบจะมีรหัสการส่ง; ข้อความจะถูกส่งทันทีหรือที่send_at
curl https://sendsmsonline.cc/api/v1/sends \
-H "Authorization: Bearer $SSO_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "recipients": [ { "to": "+447700900461", "fields": { "first_name": "Tom" } }, { "to": "+12015550142", "fields": { "first_name": "Ava" } } ], "text": "Hi {{first_name}}, your table is ready at 7:30.", "name": "Friday bookings", "client_ref": "bookings-1107" }'const res = await fetch("https://sendsmsonline.cc/api/v1/sends", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SSO_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
recipients: [{ to: "+447700900461", fields: { first_name: "Tom" } }],
text: "Hi {{first_name}}, your table is ready at 7:30.",
}),
});
const data = await res.json();
if (!res.ok) throw new Error(data.error.message);
console.log(data.send.id, data.send.cost_usd);import os, requests
r = requests.post(
"https://sendsmsonline.cc/api/v1/sends",
headers={"Authorization": f"Bearer {os.environ['SSO_API_KEY']}"},
json={
"recipients": [{"to": "+447700900461", "fields": {"first_name": "Tom"}}],
"text": "Hi {{first_name}}, your table is ready at 7:30.",
},
timeout=30,
)
data = r.json()
if r.status_code >= 400:
raise RuntimeError(data["error"]["message"])
print(data["send"]["id"], data["send"]["cost_usd"])<?php
$ch = curl_init("https://sendsmsonline.cc/api/v1/sends");
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer " . getenv("SSO_API_KEY"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"recipients" => [["to" => "+447700900461", "fields" => ["first_name" => "Tom"]]],
"text" => "Hi {{first_name}}, your table is ready at 7:30.",
]),
]);
$data = json_decode(curl_exec($ch), true);
echo $data["send"]["id"] ?? $data["error"]["message"];การตรวจสอบสิทธิ์
ส่งคีย์ของคุณในส่วนหัว Authorization: Authorization: Bearer sso_live_... คีย์มีความยาว 49 ตัวอักษรและเริ่มต้นด้วย sso_live_ สูงสุด 5 คีย์ต่อบัญชี; เพิกถอนหนึ่งคีย์ในพื้นที่ทำงานและมันจะหยุดทำงานทันที รายการราคาเป็นสาธารณะและไม่ต้องการคีย์
ข้อผิดพลาด
ข้อผิดพลาดใช้รหัสสถานะ HTTP และเนื้อหา JSON ที่มีรหัสคงที่และประโยคที่คุณสามารถแสดงให้บุคคลเห็น ไม่มีค่าใช้จ่ายเมื่อคำขอล้มเหลว
HTTP/1.1 402 Payment Required
{ "error": { "code": "insufficient_credit", "message": "Short by $3.20. Add funds to send.", "total": "8.62480", "credit": "5.42000" } }| ฟิลด์ | ประเภท | ความหมาย |
|---|---|---|
| 400 | invalid_json, text_missing, recipients_missing, too_many_recipients, too_many_segments, schedule_range, bad_send_at | คำขอต้องการการเปลี่ยนแปลง |
| 401 | unauthorized | คีย์หาย ผิด หรือถูกเพิกถอน |
| 402 | insufficient_credit | ยอดเงินไม่เพียงพอสำหรับยอดรวม |
| 404 | not_found | ไม่มีการส่ง ข้อความ ประเทศหรือปลายทางดังกล่าว |
| 409 | not_cancelable | การส่งได้เริ่มต้นแล้ว |
| 429 | rate_limited | มากกว่า 240 คำขอในหนึ่งนาที |
ข้อจำกัด
- 240 คำขอต่อนาทีต่อคีย์ แสดงใน X-RateLimit-Limit, X-RateLimit-Remaining และ X-RateLimit-Reset (วินาที unix)
- 5,000 หมายเลขต่อคำขอ, 2,000 ตัวอักษรต่อข้อความ, 10 ส่วนต่อข้อความ
- ข้อความออกได้สูงสุด 300 ต่อนาทีต่อบัญชี
- send_at จาก 10 นาทีถึง 30 วันข้างหน้า
ราคา
GET/api/v1/prices
GET/api/v1/prices/{country}
ราคาต่อข้อความ (หนึ่งส่วน) สำหรับทุกประเทศ ใน USD ด้วยทศนิยม 5 ตำแหน่ง ไม่ต้องใช้คีย์
{ "price": { "country": "GB", "name": "United Kingdom", "dial_code": "+44", "price_usd": "0.00868" }, "updated": "2026-11-07" }ยอดเงินในบัญชี
GET/api/v1/account
{ "account": "SO8K2M4Q7X9TBA", "credit_usd": "41.27660", "currency": "USD" }ประมาณค่าใช้จ่าย
POST/api/v1/costs
ใช้เนื้อหาเดียวกันกับการส่งและคืนค่าที่จะเสีย โดยไม่ส่งหรือคิดเงิน ข้อความที่รวมกันของผู้รับแต่ละคนตัดสินส่วนของมัน ดังนั้นผลลัพธ์จึงแม่นยำ
{
"recipients": 2, "segments_min": 1, "segments_max": 1, "encoding": "gsm7", "messages_billed": 2,
"total_usd": "0.01426", "credit_usd": "41.27660", "enough_credit": true,
"countries": [ { "country": "GB", "recipients": 1, "price_usd": "0.00868", "subtotal_usd": "0.00868" },
{ "country": "US", "recipients": 1, "price_usd": "0.00558", "subtotal_usd": "0.00558" } ],
"dropped": [], "too_long": null
}สร้างการส่ง
POST/api/v1/sends
ข้อความหนึ่งถึงหนึ่งหรือหลายหมายเลข เครดิตสำหรับการส่งทั้งหมดจะถูกหักเมื่อได้รับการยอมรับ ข้อความที่ล้มเหลวจะคืนเงินทีละข้อความ
| ฟิลด์ | ประเภท | ความหมาย |
|---|---|---|
| to | string or array | หมายเลขในรูปแบบสากล (+447700900461) ใช้สิ่งนี้หรือผู้รับ |
| recipients | array | วัตถุที่มี to และ fields สำหรับการรวมฟิลด์: { "to": "+1...", "fields": { "first_name": "Ava" } } |
| text | string | ข้อความ สูงสุด 2,000 ตัวอักษร {{field}} จะถูกแทนที่ต่อผู้รับ ค่าที่ขาดหายไปจะกลายเป็นค่าว่าง |
| send_at | string | เวลา ISO 8601 ที่เลือกได้พร้อมออฟเซตหรือ Z หากไม่มี การส่งจะเริ่มทันที |
| name | string | ป้ายชื่อที่เลือกได้ซึ่งแสดงในพื้นที่ทำงาน (80 ตัวอักษร) |
| client_ref | string | ข้อมูลอ้างอิงที่เลือกได้ซึ่งคืนใน webhooks (64 ตัวอักษร) |
| opt_out | boolean | เพิ่มบรรทัดปฏิเสธที่บันทึกไว้ในการตั้งค่าไปที่ท้ายข้อความ |
| default_country | string | รหัส ISO ที่ใช้สำหรับหมายเลขที่เขียนโดยไม่มีรหัสประเทศ |
HTTP/1.1 201 Created
{
"send": { "id": "CA7Q29XMAB4DFK", "status": "queued", "source": "api", "recipients": 2, "segments_max": 1,
"encoding": "gsm7", "cost_usd": "0.01426", "refunded_usd": "0.00000", "client_ref": "bookings-1107",
"send_at": null, "created_at": "2026-11-07T10:12:03.120Z", "started_at": null, "finished_at": null },
"dropped": [ { "value": "+4412", "code": "too_short", "message": "Too short" } ]
}หมายเลขที่ไม่สามารถส่งได้จะถูกระบุใน dropped และไม่เคยถูกคิดเงิน รหัส: no_country_code, too_short, too_long, not_a_number, wrong_length, not_covered, duplicate และ suppressed (ในรายการไม่ส่งของคุณ)
รับหรือแสดงรายการการส่ง
GET/api/v1/sends/{id}
GET/api/v1/sends?limit=25&before={id}
การส่งเดียวรวม counts ต่อสถานะข้อความ รายการเรียงจากใหม่สุดก่อน ส่ง next_before เป็น before สำหรับหน้าถัดไป การส่งจากพื้นที่ทำงานจะปรากฏที่นี่ด้วย โดยมี source: "web"
ข้อความ
GET/api/v1/sends/{id}/messages?status=failed&limit=100
GET/api/v1/messages/{id}
{ "message": { "id": "MS3D8RW0K2QJ7N", "send_id": "CA7Q29XMAB4DFK", "to": "+447700900461", "country": "GB",
"segments": 1, "price_usd": "0.00868", "status": "delivered", "reason": null, "reason_text": null,
"created_at": "2026-11-07T10:12:03.120Z", "sent_at": "2026-11-07T10:12:04.010Z", "done_at": "2026-11-07T10:12:09.400Z" } }ยกเลิกการส่ง
POST/api/v1/sends/{id}/cancel
เฉพาะการส่งที่กำหนดเวลาที่ยังไม่เริ่มต้นเท่านั้นที่สามารถยกเลิกได้ ค่าใช้จ่ายทั้งหมดจะคืนสู่เครดิตของคุณและคำตอบรวม refunded_usd
เว็บฮุค
ตั้งค่า URL https ในพื้นที่ทำงาน (API และ webhooks) เราจะ POST เหตุการณ์เมื่อข้อความถูกส่งหรือล้มเหลว สำหรับการส่งจาก API และพื้นที่ทำงาน ตอบด้วยสถานะ 2xx ใดๆ ภายใน 10 วินาที การส่งที่ล้มเหลวจะถูกลองอีกครั้งสูงสุด 7 ครั้งทั้งหมด: ทันที จากนั้นหลังจาก 1 นาที, 5 นาที, 30 นาที, 1 ชั่วโมง, 2 ชั่วโมง และ 3 ชั่วโมง พื้นที่ทำงานจะแสดงแต่ละความพยายามพร้อมสถานะและคำตอบ
POST https://your-server.example/sms-events
X-SSO-Event: message.delivered
X-SSO-Delivery: evt_5a0c9e31d2b7f4a68c
X-SSO-Timestamp: 1794132729
X-SSO-Signature: sha256=8f1c...e42a
{ "id": "evt_5a0c9e31d2b7f4a68c", "event": "message.delivered", "created": "2026-11-07T10:12:09.000Z",
"data": { "message": { "id": "MS3D8RW0K2QJ7N", "send_id": "CA7Q29XMAB4DFK", "to": "+447700900461", "country": "GB",
"segments": 1, "price_usd": "0.00868", "status": "delivered", "reason": null, "reason_text": null,
"client_ref": "bookings-1107", "created_at": "...", "sent_at": "...", "done_at": "..." } } }ลายเซ็นคือ HMAC-SHA256 ของ timestamp + "." + raw body ด้วยความลับในการเซ็นของคุณ (เริ่มต้นด้วย sso_whk_) ตรวจสอบบน raw body ก่อนการแยกวิเคราะห์ ปฏิเสธ timestamps ที่เก่ากว่า 5 นาที และใช้ delivery id เพื่อละเว้นการทำซ้ำ
import crypto from "node:crypto";
// rawBody: the request body exactly as received (a string), before JSON.parse
export function verify(rawBody, headers, secret) {
const ts = headers["x-sso-timestamp"];
const sig = headers["x-sso-signature"] || "";
const want = "sha256=" + crypto.createHmac("sha256", secret).update(`${ts}.${rawBody}`).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(ts)) < 300;
return fresh && sig.length === want.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(want));
}import hashlib, hmac, time
def verify(raw_body: bytes, headers, secret: str) -> bool:
ts = headers.get("X-SSO-Timestamp", "")
sig = headers.get("X-SSO-Signature", "")
mac = hmac.new(secret.encode(), f"{ts}.".encode() + raw_body, hashlib.sha256)
want = "sha256=" + mac.hexdigest()
fresh = ts.isdigit() and abs(time.time() - int(ts)) < 300
return fresh and hmac.compare_digest(sig, want)<?php
function verify(string $rawBody, string $ts, string $sig, string $secret): bool {
$want = "sha256=" . hash_hmac("sha256", $ts . "." . $rawBody, $secret);
return ctype_digit($ts) && abs(time() - (int)$ts) < 300 && hash_equals($want, $sig);
}เหตุการณ์: message.delivered, message.failed, และ test จากปุ่มส่งเหตุการณ์ทดสอบ
สถานะและเหตุผล
| ฟิลด์ | ประเภท | ความหมาย |
|---|---|---|
| queued | status | กำลังรอออกจากคิวของเรา |
| sent | status | ส่งไปยังเครือข่ายแล้ว รอรายงานการส่ง ส่วนใหญ่รายงานจะมาภายในไม่กี่นาที แต่บางเครือข่ายอาจใช้เวลาถึง 24 ชั่วโมง |
| delivered | status | เครือข่ายยืนยันว่าโทรศัพท์ได้รับข้อความแล้ว |
| failed | status | ส่งไม่สำเร็จ ราคาถูกคืนเข้าบัญชีของคุณ |
| canceled | status | ไม่ได้ส่งเพราะคุณยกเลิก เงินถูกคืนแล้ว |
สาเหตุความล้มเหลว (ฟิลด์ reason):
| ฟิลด์ | ประเภท | ความหมาย |
|---|---|---|
| network_error | reason | ข้อผิดพลาดของเครือข่าย |
| absent | reason | โทรศัพท์ปิดหรืออยู่นอกพื้นที่ให้บริการ |
| not_in_service | reason | หมายเลขไม่ให้บริการ |
| blocked | reason | ถูกบล็อกโดยเครือข่ายหรือผู้รับ |
| landline | reason | โทรศัพท์บ้านหรือหมายเลขที่ไม่สามารถรับ SMS ได้ |
| content_filter | reason | ถูกปฏิเสธโดยตัวกรองเนื้อหาของเครือข่าย |
| expired | reason | หมดอายุ: ไม่มีรายงานก่อนเวลาที่เครือข่ายกำหนด |
| canceled | reason | ยกเลิกก่อนส่ง |
| unknown | reason | ไม่ทราบการตอบสนองจากเครือข่าย |
การตรวจสอบบริการอยู่ที่ หน้าสถานะ และการเปลี่ยนแปลง API ใน ประวัติการอัปเดต