Preview SMS POST
ใช้คำนวณเครดิตที่จะใช้และชนิดการเข้ารหัสของข้อความ โดยไม่ส่งจริง และไม่หักเครดิต รับ body รูปแบบเดียวกับ ส่ง SMS
Authorization
ใช้ API Key (การยืนยันตัวตน) ส่งใน header Authorization: Bearer <API_KEY>
HTTP Request
http
POST https://public-api.smsup-plus.com/sms/previewContent Type
application/json (รับเฉพาะ JSON)
Parameter Description
ใช้ body เดียวกับ ส่ง SMS ฟิลด์ที่มีผลต่อการคำนวณ:
| Property | Type | Required | Description |
|---|---|---|---|
messages | array | Required | อย่างน้อย 1 รายการ |
messages[].from | string | Required | ต้องไม่ว่าง (ไม่ตรวจสิทธิ์ผู้ส่ง) |
messages[].destinations | array | Required | อย่างน้อย 1 รายการ และทุกรายการต้องมี to (ไม่ตรวจรูปแบบเบอร์) |
messages[].text | string | Required | ข้อความที่ต้องการคำนวณ |
messages[].shorturl | string | Optional | Y = คิดเครดิตโดยนับ URL เป็นความยาวลิงก์สั้น |
messages[].sendAt | string | Optional | ถ้าส่งมาต้องเป็นรูปแบบ RFC3339 |
ฟิลด์อื่น (bulkId, notifyUrl, messageId ฯลฯ) รับได้แต่ไม่มีผลกับผลลัพธ์
Response Description
| Property | Type | Description |
|---|---|---|
status | number | 200 |
data.totalCredit | number | เครดิตรวม = ผลรวมของ (เครดิตต่อเบอร์ × จำนวน destinations) ทุก message — นับทุกเบอร์ที่ส่งมา รวมเบอร์ที่อาจถูกปฏิเสธตอนส่งจริง |
data.creditPerMessage | number | เครดิตต่อเบอร์ของ message แรก (รวมผลของ shorturl) |
data.messageCount | number | จำนวน SMS part ของ text ใน message แรก (ไม่รวมผลของ shorturl) |
data.encoding | string | การเข้ารหัสของ message แรก: ascii = ชุดอักขระมาตรฐาน, thai = Unicode (มีอักขระนอกชุดมาตรฐาน ไม่จำเป็นต้องเป็นภาษาไทย) |
กติกาการนับ part ดูที่ การคิดเครดิต
ตัวอย่าง Request
bash
curl -X POST 'https://public-api.smsup-plus.com/sms/preview' \
-H 'Authorization: Bearer <API_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"messages": [
{
"from": "MyBrand",
"destinations": [{ "to": "0812345678" }, { "to": "0898765432" }],
"text": "สวัสดีครับ คำสั่งซื้อของคุณจัดส่งแล้ว"
}
]
}'js
const res = await fetch('https://public-api.smsup-plus.com/sms/preview', {
method: 'POST',
headers: { Authorization: 'Bearer <API_KEY>', 'Content-Type': 'application/json' },
body: JSON.stringify({
messages: [
{
from: 'MyBrand',
destinations: [{ to: '0812345678' }, { to: '0898765432' }],
text: 'สวัสดีครับ คำสั่งซื้อของคุณจัดส่งแล้ว',
},
],
}),
})
console.log(await res.json())ตัวอย่าง Response
json
{
"status": 200,
"data": {
"totalCredit": 2,
"creditPerMessage": 1,
"messageCount": 1,
"encoding": "thai"
}
}Error ที่อาจเจอ
ดูภาพรวมที่ รหัสข้อผิดพลาด
| HTTP | Response | สาเหตุ |
|---|---|---|
| 400 | {"error":{"statusCode":"400","description":"Invalid request body","message":"BAD_REQUEST"}} | body ไม่ใช่ JSON ที่ถูกต้อง หรือไม่มี / มี messages ว่าง |
| 400 | {"error":{"statusCode":"400","description":"Destinations not found","message":"BAD_REQUEST"}} | message ไม่มี destinations หรือมีรายการที่ to ว่าง |
| 400 | {"error":{"statusCode":"400","description":"Text not found","message":"BAD_REQUEST"}} | text ว่าง |
| 400 | {"error":{"statusCode":"400","description":"sender not found","message":"BAD_REQUEST"}} | from ว่าง |
| 400 | {"error":{"statusCode":"400","description":"sendAt must be in RFC3339 format (e.g. 2026-04-10T09:00:00+07:00)","message":"BAD_REQUEST"}} | sendAt ผิดรูปแบบ |
| 429 | {"error":{"statusCode":"429","description":"rate limit exceeded: max 50 requests per second per account","message":"TOO_MANY_REQUESTS"}} | เรียกถี่เกินกำหนด — รอตาม header Retry-After |
Preview ไม่ได้ตรวจทุกอย่างเหมือนการส่งจริง
Preview ไม่ตรวจสิทธิ์ผู้ส่ง ยอดเครดิตคงเหลือ รูปแบบเบอร์ ความยาวสูงสุด 1,600 ตัวอักษร หรือจำนวนเบอร์สูงสุด — คำขอที่ Preview ผ่านอาจยังถูกปฏิเสธที่ ส่ง SMS
