สารบัญหน้านี้ (21)
- ภาพรวม
- Workflow: แก้ข้อความเตือนนัด → ทดสอบ → อนุมัติ → เผยแพร่
- Workflow: แม่แบบเดียว แสดงผล 4 ช่องทาง 2 ภาษา
- The Template object
- The TemplateVersion object
- Endpoints (10)
- GETรายการแม่แบบ
- POSTสร้างแม่แบบ
- GETดูแม่แบบ
- PATCHแก้ข้อมูลแม่แบบ
- POSTสร้างเวอร์ชันใหม่ (ฉบับร่าง)
- GETประวัติเวอร์ชัน
- POSTส่งตรวจ / อนุมัติ / ไม่อนุมัติ
- POSTเผยแพร่เวอร์ชัน
- POSTทดสอบแสดงผล
- DELETEลบ/เก็บถาวรแม่แบบ
- Webhooks (5)
- Errors
- Rate limit
- Changelog
- เครื่องมือ: ตัวแสดงผลแม่แบบ
- SIANG Notify
- Docs
- Notification API
- Template
SIANG Messaging API · โมดูล Template
Template API
เก็บข้อความทุกช่องทางไว้ที่เดียวในรูปแม่แบบหลายภาษา มีตัวแปรและตัวกรอง (วันที่ไทย เวลา เงิน) เวอร์ชันพร้อมขั้นอนุมัติ และทดสอบแสดงผลก่อนใช้จริง — ระบบของคุณส่งแค่รหัสแม่แบบกับตัวแปร
- 10endpoint
- 4ช่องทาง
- ไทย · อังกฤษภาษา
- 6ตัวแปรเตือนนัด

ภาพรวมโมดูล Template
ทำอะไรได้
- 1 แม่แบบมีเนื้อหาได้ 4 ช่องทาง (อีเมล SMS LINE Push) × 2 ภาษา (ไทย/อังกฤษ)
- ตัวแปร {{customer_name}} + ตัวกรอง {{appointment_at|date}} {{x|default:"…"}}
- ประกาศชนิดตัวแปร (string datetime url number) ตรวจตอนส่ง
- เวอร์ชัน + ขั้นอนุมัติ 2 คน + ย้อนกลับได้
- ทดสอบแสดงผลพร้อมนับ segment SMS ก่อนเผยแพร่
ใช้เมื่อไร
- ข้อความที่ส่งอัตโนมัติจากระบบ (ยืนยัน/เตือนนัด ใบเสร็จ)
- ให้ทีมการตลาดแก้ข้อความเองโดยไม่ต้องแก้โค้ด
- ต้องมีหลักฐานว่าใครแก้/อนุมัติข้อความที่ส่งถึงลูกค้า
Base path
/v1/templates/v1/templates/{id}/versions/v1/templates/{id}/render
การยืนยันตัวตนและสิทธิ์ (scope)
ทุกคำขอส่งหัว Authorization: Bearer <API key> — key ของ Sandbox ขึ้นต้น sg_test_ ใช้กับ https://sandbox.api.siang.example (ไม่ส่งถึงผู้รับจริง ยกเว้นผู้รับทดสอบที่ยืนยันแล้ว) · key ของ Production ขึ้นต้น sg_live_ ใช้กับ https://api.siang.example · เลือกเวอร์ชันด้วยหัว Siang-Version: 2026-08-01 · key แต่ละตัวกำหนด scope ได้ในแดชบอร์ด ให้แต่ละระบบได้เฉพาะสิทธิ์ที่ใช้
| scope | อนุญาตให้ | endpoint ที่ใช้ |
|---|---|---|
templates:read | ดูแม่แบบ เวอร์ชัน ทดสอบแสดงผล | GET /v1/templates · /{id} · /versions · POST /render |
templates:write | สร้าง/แก้/ลบ แม่แบบและฉบับร่าง ส่งตรวจ | POST · PATCH · DELETE /v1/templates · /versions · review submit |
templates:approve | อนุมัติ/ไม่อนุมัติ และเผยแพร่ | review approve/reject · POST /publish |
Object หลัก
Templateแม่แบบ 1 ชุด — ตัวอย่างคือ tpl_appointment_reminder ที่ใช้ทุกช่องทางในเอกสารนี้18 ฟิลด์TemplateVersionเนื้อหา 1 เวอร์ชัน (แก้ไม่ได้หลังส่งตรวจ) — ตัวอย่างคือเวอร์ชัน 3 ที่เผยแพร่อยู่13 ฟิลด์
ความสัมพันธ์กับโมดูลอื่น
- Emailใช้ template.id ใน POST /v1/emails
- SMSช่อง sms — ตรวจจำนวน segment ด้วยตัวนับ
- LINEช่อง line_title / line_body กลายเป็นการ์ด
- Push Notificationช่อง push_title / push_body — ดูการตัดข้อความบนจอล็อก
- Historyข้อความทุกฉบับบันทึกเวอร์ชันแม่แบบที่ใช้
ข้อควรรู้
- รายการแบบ cursorendpoint ที่คืนรายการใช้ limit (1–100) + starting_after/ending_before · ผลมี has_more และ next_cursor — อย่าใช้เลขหน้า เพราะรายการใหม่เข้ามาตลอด
- Idempotency-Keyทุก POST ที่ส่งข้อความหรือสร้างรายการรับหัว Idempotency-Key (UUID v4) · ส่งซ้ำภายใน 24 ชม. ได้ผลเดิมและไม่ส่งข้อความซ้ำถึงลูกค้า
- เวลา ISO 8601 +07:00ทุกเวลาในคำขอ/ผลลัพธ์เป็น ISO 8601 พร้อมโซนเวลา เช่น 2026-10-12T10:00:00+07:00 · ส่งแบบ Z (UTC) ได้ ระบบแปลงให้
- เงินเป็นสตางค์ค่าใช้จ่าย (cost) เป็นจำนวนเต็มหน่วยสตางค์ เช่น 90 = ฿0.90 · ไม่มีทศนิยมจึงไม่มีปัญหาปัดเศษ
- ข้อมูลส่วนบุคคล (PDPA)ผลลัพธ์ใน production ปิดบังเบอร์/อีเมล (08x-xxx-0147 · sir***@…) ยกเว้น key ที่มี scope pii:read · เนื้อหาข้อความเก็บ 90 วัน metadata 2 ปี
- ตัวกรองที่รองรับdate (อ. 13 ต.ค. 2569) · time (14:30 น.) · datetime · upper · baht (สตางค์ → ฿) · default:"ค่า" — ภาษาอังกฤษจัดรูปตาม locale=en อัตโนมัติ
Workflow — ลำดับการทำงานจริง (2 เรื่อง)
แต่ละเรื่องดูได้ 2 แบบ: ภาพรวม อธิบายทีละขั้นแบบภาษาคน และ Sequence ทีละขั้น กดเล่นหรือคลิกลูกศรเพื่อดูคำขอ/ผลลัพธ์จริงของขั้นนั้น · เส้นประ = ไม่รอผล (คิว/webhook)
แก้ข้อความเตือนนัด → ทดสอบ → อนุมัติ → เผยแพร่
ทีมการตลาดเพิ่มบรรทัด “มาก่อน 15 นาที” — ทดสอบแสดงผลเจอตัวแปรผิดชนิด แก้แล้วส่งให้ผู้จัดการอนุมัติ
- ทีมการตลาดผู้แก้
- หลังบ้านคลินิก
- SIANG API
- ผู้จัดการคลินิกผู้อนุมัติ
- ระบบนัด
- 1
ทีมการตลาด → หลังบ้านคลินิก
เพิ่มบรรทัดในช่อง SMS และ LINE
- 2
หลังบ้านคลินิก → SIANG API
สร้างเวอร์ชัน 4 จากเวอร์ชัน 3
POST /v1/templates/tpl_appointment_reminder/versions - 3
หลังบ้านคลินิก → SIANG API
ทดสอบด้วยค่าตัวอย่างที่พิมพ์เองว่า “พรุ่งนี้บ่ายสอง”
POST /v1/templates/tpl_appointment_reminder/render - 4
SIANG API → หลังบ้านคลินิก
appointment_at ต้องเป็นเวลา ISO 8601 — หลังบ้านไฮไลต์ช่องที่ผิด
- 5
หลังบ้านคลินิก → SIANG API
ใช้ค่าจากนัดจริง ได้ผลทุกช่องทาง SMS ยาว 2 segment
POST /v1/templates/tpl_appointment_reminder/render - 6
หลังบ้านคลินิก → SIANG API
ส่งให้ผู้อนุมัติ
POST /v1/templates/tpl_appointment_reminder/versions/4/review - 7
SIANG API → ผู้จัดการคลินิก
webhook template.version.submitted → หลังบ้านส่งอีเมลถึงผู้จัดการ
ไม่รอผล (async) - 8
ผู้จัดการคลินิก → SIANG API
ผู้จัดการเทียบความต่างกับเวอร์ชัน 3 แล้วอนุมัติ
POST /v1/templates/tpl_appointment_reminder/versions/4/review - 9
ผู้จัดการคลินิก → SIANG API
เผยแพร่เวอร์ชัน 4
POST /v1/templates/tpl_appointment_reminder/publish - 10
SIANG API → ระบบนัด
ระบบนัดไม่ต้องแก้โค้ด — การส่งรอบ 10:00 พรุ่งนี้ใช้เวอร์ชัน 4 อัตโนมัติ
POST /hooks/siangไม่รอผล (async)
ฉบับใหม่ใช้จริงภายในวันเดียว · SMS ยังเป็น 2 segment (ค่าใช้จ่ายไม่เพิ่ม) · มีบันทึกผู้แก้/ผู้อนุมัติครบ
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 ทีมการตลาด หลังบ้านคลินิก
แก้เนื้อหา
เพิ่มบรรทัดในช่อง SMS และ LINE
2 หลังบ้านคลินิก SIANG API
POST …/versions
สร้างเวอร์ชัน 4 จากเวอร์ชัน 3
POST /v1/templates/tpl_appointment_reminder/versions HTTP/1.1
Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1
{
"base_version": 3,
"change_note": "เพิ่มบรรทัด “กรุณามาก่อนเวลา 15 นาที” ทุกช่องทาง"
}HTTP/1.1 201 Created
{
"id": "tplv_4",
"version": 4,
"status": "draft"
}3 หลังบ้านคลินิก SIANG API
POST …/render
ทดสอบด้วยค่าตัวอย่างที่พิมพ์เองว่า “พรุ่งนี้บ่ายสอง”
POST /v1/templates/tpl_appointment_reminder/render HTTP/1.1
Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1
{
"version": 4,
"variables": {
"customer_name": "ศิริพร",
"appointment_at": "พรุ่งนี้บ่ายสอง",
"branch_name": "อารีย์",
"service_name": "ทรีตเมนต์เลเซอร์ผิวใส",
"doctor_name": "พญ.กานต์ธิดา",
"confirm_url": "https://phiwsai.example/a/0318"
}
}4 SIANG API หลังบ้านคลินิก
422 variable_type_mismatch
appointment_at ต้องเป็นเวลา ISO 8601 — หลังบ้านไฮไลต์ช่องที่ผิด
HTTP/1.1 422 Unprocessable Entity
{
"error": {
"code": "variable_type_mismatch",
"variable": "appointment_at"
}
}5 หลังบ้านคลินิก SIANG API
POST …/render
ใช้ค่าจากนัดจริง ได้ผลทุกช่องทาง SMS ยาว 2 segment
POST /v1/templates/tpl_appointment_reminder/render HTTP/1.1
Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1
{
"version": 4,
"variables": {
"customer_name": "ศิริพร",
"appointment_at": "2026-10-13T14:30:00+07:00",
"branch_name": "อารีย์",
"service_name": "ทรีตเมนต์เลเซอร์ผิวใส",
"doctor_name": "พญ.กานต์ธิดา",
"confirm_url": "https://phiwsai.example/a/0318"
}
}HTTP/1.1 200 OK
{
"rendered": {
"sms": {
"segments": 2
}
}
}6 หลังบ้านคลินิก SIANG API
review: submit
ส่งให้ผู้อนุมัติ
POST /v1/templates/tpl_appointment_reminder/versions/4/review HTTP/1.1
Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1
{
"action": "submit"
}7 SIANG API ผู้จัดการคลินิกasync
อีเมลแจ้งรออนุมัติ
webhook template.version.submitted → หลังบ้านส่งอีเมลถึงผู้จัดการ
8 ผู้จัดการคลินิก SIANG API
review: approve
ผู้จัดการเทียบความต่างกับเวอร์ชัน 3 แล้วอนุมัติ
POST /v1/templates/tpl_appointment_reminder/versions/4/review HTTP/1.1
Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1
{
"action": "approve",
"comment": "ผ่าน"
}9 ผู้จัดการคลินิก SIANG API
POST …/publish
เผยแพร่เวอร์ชัน 4
POST /v1/templates/tpl_appointment_reminder/publish HTTP/1.1
Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1
{
"version": 4
}HTTP/1.1 200 OK
{
"published_version": 4
}10 SIANG API ระบบนัดasync
webhook template.published
ระบบนัดไม่ต้องแก้โค้ด — การส่งรอบ 10:00 พรุ่งนี้ใช้เวอร์ชัน 4 อัตโนมัติ
POST /hooks/siang HTTP/1.1
{
"type": "template.published",
"data": {
"id": "tpl_appointment_reminder",
"published_version": 4,
"previous_version": 3
}
}HTTP/1.1 200 OKฉบับใหม่ใช้จริงภายในวันเดียว · SMS ยังเป็น 2 segment (ค่าใช้จ่ายไม่เพิ่ม) · มีบันทึกผู้แก้/ผู้อนุมัติครบ
แม่แบบเดียว แสดงผล 4 ช่องทาง 2 ภาษา
ตอนส่ง ระบบเลือกภาษาตามผู้รับและเลือกช่องตามช่องทางที่ส่งได้ — ระบบนัดส่งแค่ template id + ตัวแปรชุดเดียว
- ระบบนัด
- SIANG API
- ตัวแสดงผลแม่แบบ
- ข้อมูลผู้รับภาษา ความยินยอม
- ช่องทางส่งอีเมล SMS LINE Push
- 1
ระบบนัด → SIANG API
ส่งด้วย template id + ตัวแปร + fallback (ไม่มีข้อความในคำขอเลย)
POST /v1/line/messages - 2
SIANG API → ข้อมูลผู้รับ
ผู้รับตั้งภาษาไทย (locale=th) และมี line_user_id
- 3
SIANG API → ตัวแสดงผลแม่แบบ
ใช้เวอร์ชันที่เผยแพร่ (3) ช่อง line_title + line_body
- 4
ตัวแสดงผลแม่แบบ → SIANG API
หัวข้อ “พรุ่งนี้มีนัดที่ผิวใส คลินิก”
- 5
SIANG API → ช่องทางส่ง
ส่งการ์ด — ผู้รับบล็อก OA
- 6
SIANG API → ตัวแสดงผลแม่แบบ
fallback: ใช้แม่แบบเดิมช่อง sms กับตัวแปรชุดเดิม
ไม่รอผล (async) - 7
ตัวแสดงผลแม่แบบ → SIANG API
“ผิวใส คลินิก: เตือนนัดคุณศิริพร อ. 13 ต.ค. 2569 14:30 น. สาขาอารีย์ ยืนยัน/เลื่อน https://phiwsai.example/a/0318”
- 8
SIANG API → ช่องทางส่ง
ส่ง SMS สำเร็จ บันทึกว่าใช้ tpl_appointment_reminder v3 ช่อง sms
- 9
SIANG API → ระบบนัด
ระบบนัดได้ผลระดับข้อความ: ส่งถึงทาง SMS พร้อมเวอร์ชันแม่แบบที่ใช้
POST /hooks/siangไม่รอผล (async)
ตัวแปร 6 ตัวชุดเดียว → 7 ช่องข้อความ × 2 ภาษา · เปลี่ยนข้อความได้โดยไม่ deploy ระบบนัด
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 ระบบนัด SIANG API
POST /v1/line/messages
ส่งด้วย template id + ตัวแปร + fallback (ไม่มีข้อความในคำขอเลย)
POST /v1/line/messages HTTP/1.1
Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1
{
"to": "rcp_7Tm4",
"template": {
"id": "tpl_appointment_reminder",
"variables": {
"customer_name": "ศิริพร",
"appointment_at": "2026-10-13T14:30:00+07:00",
"branch_name": "อารีย์",
"service_name": "ทรีตเมนต์เลเซอร์ผิวใส",
"doctor_name": "พญ.กานต์ธิดา",
"confirm_url": "https://phiwsai.example/a/0318"
}
},
"fallback": {
"channels": [
"sms"
]
}
}HTTP/1.1 202 Accepted
{
"id": "lmsg_01JC4R7Q8B",
"status": "queued"
}2 SIANG API ข้อมูลผู้รับ
อ่าน locale
ผู้รับตั้งภาษาไทย (locale=th) และมี line_user_id
3 SIANG API ตัวแสดงผลแม่แบบ
แสดงผลช่อง line (th)
ใช้เวอร์ชันที่เผยแพร่ (3) ช่อง line_title + line_body
4 ตัวแสดงผลแม่แบบ SIANG API
การ์ดพร้อมส่ง
หัวข้อ “พรุ่งนี้มีนัดที่ผิวใส คลินิก”
HTTP/1.1 200 OK
{
"channel": "line",
"title": "พรุ่งนี้มีนัดที่ผิวใส คลินิก",
"body": "คุณศิริพร · ทรีตเมนต์เลเซอร์ผิวใส\nอ. 13 ต.ค. 2569 14:30 น.\nสาขาอารีย์ · พญ.กานต์ธิดา"
}5 SIANG API ช่องทางส่ง
ส่ง LINE
ส่งการ์ด — ผู้รับบล็อก OA
6 SIANG API ตัวแสดงผลแม่แบบasync
แสดงผลช่อง sms (th)
fallback: ใช้แม่แบบเดิมช่อง sms กับตัวแปรชุดเดิม
7 ตัวแสดงผลแม่แบบ SIANG API
2 segment
“ผิวใส คลินิก: เตือนนัดคุณศิริพร อ. 13 ต.ค. 2569 14:30 น. สาขาอารีย์ ยืนยัน/เลื่อน https://phiwsai.example/a/0318”
8 SIANG API ช่องทางส่ง
ส่ง SMS
ส่ง SMS สำเร็จ บันทึกว่าใช้ tpl_appointment_reminder v3 ช่อง sms
9 SIANG API ระบบนัดasync
webhook message.delivered
ระบบนัดได้ผลระดับข้อความ: ส่งถึงทาง SMS พร้อมเวอร์ชันแม่แบบที่ใช้
POST /hooks/siang HTTP/1.1
{
"type": "message.delivered",
"data": {
"id": "msg_01JC4R7K2D",
"final_channel": "sms",
"template": {
"id": "tpl_appointment_reminder",
"version": 3,
"locale": "th"
}
}
}HTTP/1.1 200 OKตัวแปร 6 ตัวชุดเดียว → 7 ช่องข้อความ × 2 ภาษา · เปลี่ยนข้อความได้โดยไม่ deploy ระบบนัด
Objects
โครงข้อมูลที่ endpoint ของโมดูลนี้คืนกลับ — ฟิลด์ อ่านอย่างเดียว ระบบกำหนดเอง ส่งมาจะถูกละเว้น · ฟิลด์ใหม่อาจเพิ่มได้โดยไม่เปลี่ยนเวอร์ชัน (โค้ดควรไม่พังเมื่อเจอฟิลด์ที่ไม่รู้จัก)
The Template object
แม่แบบ 1 ชุด — ตัวอย่างคือ tpl_appointment_reminder ที่ใช้ทุกช่องทางในเอกสารนี้
idstringไม่บังคับอ่านอย่างเดียวรหัส
objectstringไม่บังคับอ่านอย่างเดียวชนิด
namestringไม่บังคับชื่อ
descriptionstringไม่บังคับคำอธิบาย
categorystringไม่บังคับประเภท
channelsarray<string>ไม่บังคับช่องทางที่มีเนื้อหา
localesarray<string>ไม่บังคับภาษาที่มี
default_localestringไม่บังคับภาษาตั้งต้น
variablesarray<object>ไม่บังคับประกาศตัวแปร (ชนิดใช้ตรวจตอนส่ง)
ฟิลด์ย่อยของ
variables(5)namestringจำเป็นชื่อ a-z 0-9 _
typestringจำเป็นชนิด
requiredbooleanไม่บังคับบังคับหรือไม่
descstringไม่บังคับคำอธิบาย
examplestringไม่บังคับค่าตัวอย่าง (ใช้ตอนทดสอบ)
statusstringไม่บังคับอ่านอย่างเดียวสถานะ
current_versionintegerไม่บังคับอ่านอย่างเดียวเวอร์ชันล่าสุด
published_versionintegerไม่บังคับอ่านอย่างเดียวเวอร์ชันที่ใช้ส่ง
draft_versionintegerไม่บังคับอ่านอย่างเดียวฉบับร่างที่ค้าง
tagsarray<string>ไม่บังคับป้าย
usageobjectไม่บังคับอ่านอย่างเดียวการใช้
ฟิลด์ย่อยของ
usage(2)last_30dintegerไม่บังคับข้อความ 30 วัน
last_sent_atstring · date-timeไม่บังคับส่งล่าสุด
created_bystringไม่บังคับผู้สร้าง
created_atstring · date-timeไม่บังคับอ่านอย่างเดียวสร้างเมื่อ
updated_atstring · date-timeไม่บังคับอ่านอย่างเดียวแก้ล่าสุด
{
"id": "tpl_appointment_reminder",
"object": "template",
"name": "เตือนนัดล่วงหน้า 1 วัน",
"description": "ใช้ได้ทุกช่องทาง — ระบบนัดเรียกอัตโนมัติ 10:00 ของวันก่อนนัด",
"category": "transactional",
"channels": [
"email",
"sms",
"line",
"push"
],
"locales": [
"th",
"en"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "appointment_at",
"type": "datetime",
"required": true,
"desc": "วันเวลานัด ISO 8601",
"example": "2026-10-13T14:30:00+07:00"
},
{
"name": "branch_name",
"type": "string",
"required": true,
"desc": "ชื่อสาขา",
"example": "อารีย์"
},
{
"name": "service_name",
"type": "string",
"required": true,
"desc": "บริการที่นัด",
"example": "ทรีตเมนต์เลเซอร์ผิวใส"
},
{
"name": "doctor_name",
"type": "string",
"required": false,
"desc": "แพทย์ผู้ดูแล",
"example": "พญ.กานต์ธิดา"
},
{
"name": "confirm_url",
"type": "url",
"required": true,
"desc": "ลิงก์ยืนยัน/เลื่อนนัด (https)",
"example": "https://phiwsai.example/a/0318"
}
],
"status": "published",
"current_version": 3,
"published_version": 3,
"draft_version": null,
"tags": [
"appointment"
],
"usage": {
"last_30d": 4180,
"last_sent_at": "2026-10-12T10:00:00+07:00"
},
"created_by": "usr_marketing_01",
"created_at": "2026-02-24T14:00:00+07:00",
"updated_at": "2026-09-02T11:30:00+07:00"
}
The TemplateVersion object
เนื้อหา 1 เวอร์ชัน (แก้ไม่ได้หลังส่งตรวจ) — ตัวอย่างคือเวอร์ชัน 3 ที่เผยแพร่อยู่
idstringไม่บังคับอ่านอย่างเดียวรหัส
objectstringไม่บังคับอ่านอย่างเดียวชนิด
template_idstringไม่บังคับแม่แบบ
versionintegerไม่บังคับอ่านอย่างเดียวเลขเวอร์ชัน
statusstringไม่บังคับอ่านอย่างเดียวสถานะ
contentobjectไม่บังคับเนื้อหาต่อภาษา → ต่อช่องทาง (th / en)
ฟิลด์ย่อยของ
content(2)thobjectไม่บังคับภาษาไทย
ฟิลด์ย่อยของ
th(7)email_subjectstringไม่บังคับหัวเรื่องอีเมล
email_textstringไม่บังคับเนื้อหาอีเมล
smsstringไม่บังคับข้อความ SMS
line_titlestringไม่บังคับหัวข้อการ์ด LINE ≤ 40
line_bodystringไม่บังคับเนื้อหาการ์ด LINE
push_titlestringไม่บังคับหัวข้อ push
push_bodystringไม่บังคับเนื้อหา push
enobjectไม่บังคับภาษาอังกฤษ (ช่องเดียวกัน)
change_notestringไม่บังคับสิ่งที่เปลี่ยน
submitted_bystringไม่บังคับผู้ส่งตรวจ
submitted_atstring · date-timeไม่บังคับส่งตรวจเมื่อ
approved_bystringไม่บังคับผู้อนุมัติ
approved_atstring · date-timeไม่บังคับอนุมัติเมื่อ
published_atstring · date-timeไม่บังคับเผยแพร่เมื่อ
created_atstring · date-timeไม่บังคับอ่านอย่างเดียวสร้างเมื่อ
{
"id": "tplv_3",
"object": "template_version",
"template_id": "tpl_appointment_reminder",
"version": 3,
"status": "published",
"content": {
"th": {
"email_subject": "เตือนนัด {{service_name}} {{appointment_at|date}}",
"email_text": "สวัสดีค่ะ คุณ{{customer_name}}\n\nผิวใส คลินิก ขอเตือนนัดของคุณ\nบริการ: {{service_name}}\nวันเวลา: {{appointment_at|datetime}}\nสาขา: {{branch_name}}\nแพทย์: {{doctor_name|default:\"แพทย์ประจำสาขา\"}}\n\nยืนยันหรือขอเลื่อนนัด: {{confirm_url}}",
"sms": "ผิวใส คลินิก: เตือนนัดคุณ{{customer_name}} {{appointment_at|date}} {{appointment_at|time}} สาขา{{branch_name}} ยืนยัน/เลื่อน {{confirm_url}}",
"line_title": "พรุ่งนี้มีนัดที่ผิวใส คลินิก",
"line_body": "คุณ{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\nสาขา{{branch_name}} · {{doctor_name|default:\"แพทย์ประจำสาขา\"}}",
"push_title": "วันนี้ {{appointment_at|time}} นัด{{service_name}}",
"push_body": "สาขา{{branch_name}} กับ{{doctor_name|default:\"แพทย์ประจำสาขา\"}} · แตะเพื่อยืนยันหรือเลื่อนนัด"
},
"en": {
"email_subject": "Reminder: {{service_name}} on {{appointment_at|date}}",
"email_text": "Hi {{customer_name}},\n\nThis is a reminder of your appointment at PhiwSai Clinic.\nService: {{service_name}}\nWhen: {{appointment_at|datetime}}\nBranch: {{branch_name}}\nDoctor: {{doctor_name|default:\"on-duty doctor\"}}\n\nConfirm or reschedule: {{confirm_url}}",
"sms": "PhiwSai Clinic: {{customer_name}}, your appointment is {{appointment_at|date}} {{appointment_at|time}} at {{branch_name}}. Confirm: {{confirm_url}}",
"line_title": "Your appointment is tomorrow",
"line_body": "{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\n{{branch_name}} · {{doctor_name|default:\"on-duty doctor\"}}",
"push_title": "Today {{appointment_at|time}}: {{service_name}}",
"push_body": "{{branch_name}} with {{doctor_name|default:\"on-duty doctor\"}} · tap to confirm"
}
},
"change_note": "เพิ่มชื่อแพทย์ (doctor_name ไม่บังคับ มีค่าตั้งต้น) และลิงก์ยืนยัน/เลื่อนนัด",
"submitted_by": "usr_marketing_01",
"submitted_at": "2026-09-01T16:20:00+07:00",
"approved_by": "usr_manager_02",
"approved_at": "2026-09-02T11:25:00+07:00",
"published_at": "2026-09-02T11:30:00+07:00",
"created_at": "2026-09-01T15:02:00+07:00"
}Endpoints (10)
| Method | Path | ทำอะไร | scope |
|---|---|---|---|
| GET | /v1/templates | รายการแม่แบบ | templates:read |
| POST | /v1/templates | สร้างแม่แบบ | templates:write |
| GET | /v1/templates/{template_id} | ดูแม่แบบ | templates:read |
| PATCH | /v1/templates/{template_id} | แก้ข้อมูลแม่แบบ | templates:write |
| POST | /v1/templates/{template_id}/versions | สร้างเวอร์ชันใหม่ (ฉบับร่าง) | templates:write |
| GET | /v1/templates/{template_id}/versions | ประวัติเวอร์ชัน | templates:read |
| POST | /v1/templates/{template_id}/versions/{version}/review | ส่งตรวจ / อนุมัติ / ไม่อนุมัติ | templates:writetemplates:approve |
| POST | /v1/templates/{template_id}/publish | เผยแพร่เวอร์ชัน | templates:approve |
| POST | /v1/templates/{template_id}/render | ทดสอบแสดงผล | templates:read |
| DELETE | /v1/templates/{template_id} | ลบ/เก็บถาวรแม่แบบ | templates:write |
รายการแม่แบบ
ค้นแม่แบบตามช่องทาง สถานะ ประเภท ป้าย และชื่อ
Query parametersquery
limitintegerไม่บังคับจำนวนต่อหน้า
starting_afterstringไม่บังคับcursor — รหัสรายการสุดท้ายของหน้าก่อน (ใช้ค่า next_cursor)
ending_beforestringไม่บังคับcursor ย้อนกลับ — รหัสรายการแรกของหน้าปัจจุบัน
channelstringไม่บังคับมีช่องทางนี้
statusstringไม่บังคับสถานะ
categorystringไม่บังคับประเภท
qstringไม่บังคับค้นชื่อ/คำอธิบาย
sortstringไม่บังคับการเรียง (- = มากไปน้อย)
ผลลัพธ์
- 200รายการ
- 400
invalid_requestคำขอไม่ถูกต้อง
curl -X GET "https://sandbox.api.siang.example/v1/templates?limit=20&q=%E0%B8%99%E0%B8%B1%E0%B8%94" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Siang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates?limit=20&q=%E0%B8%99%E0%B8%B1%E0%B8%94', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Siang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.get(
"https://sandbox.api.siang.example/v1/templates?limit=20&q=%E0%B8%99%E0%B8%B1%E0%B8%94",
headers={
"Authorization": f"Bearer {API_KEY}",
"Siang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v1/templates",
"data": [
{
"id": "tpl_appointment_reminder",
"object": "template",
"name": "เตือนนัดล่วงหน้า 1 วัน",
"description": "ใช้ได้ทุกช่องทาง — ระบบนัดเรียกอัตโนมัติ 10:00 ของวันก่อนนัด",
"category": "transactional",
"channels": [
"email",
"sms",
"line",
"push"
],
"locales": [
"th",
"en"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "appointment_at",
"type": "datetime",
"required": true,
"desc": "วันเวลานัด ISO 8601",
"example": "2026-10-13T14:30:00+07:00"
},
{
"name": "branch_name",
"type": "string",
"required": true,
"desc": "ชื่อสาขา",
"example": "อารีย์"
},
{
"name": "service_name",
"type": "string",
"required": true,
"desc": "บริการที่นัด",
"example": "ทรีตเมนต์เลเซอร์ผิวใส"
},
{
"name": "doctor_name",
"type": "string",
"required": false,
"desc": "แพทย์ผู้ดูแล",
"example": "พญ.กานต์ธิดา"
},
{
"name": "confirm_url",
"type": "url",
"required": true,
"desc": "ลิงก์ยืนยัน/เลื่อนนัด (https)",
"example": "https://phiwsai.example/a/0318"
}
],
"status": "published",
"current_version": 3,
"published_version": 3,
"draft_version": null,
"tags": [
"appointment"
],
"usage": {
"last_30d": 4180,
"last_sent_at": "2026-10-12T10:00:00+07:00"
},
"created_by": "usr_marketing_01",
"created_at": "2026-02-24T14:00:00+07:00",
"updated_at": "2026-09-02T11:30:00+07:00"
},
{
"id": "tpl_appointment_confirmed",
"object": "template",
"name": "ยืนยันการจองนัด",
"description": "ใช้ได้ทุกช่องทาง — ระบบนัดเรียกอัตโนมัติ 10:00 ของวันก่อนนัด",
"category": "transactional",
"channels": [
"email",
"line"
],
"locales": [
"th",
"en"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "appointment_at",
"type": "datetime",
"required": true,
"desc": "วันเวลานัด ISO 8601",
"example": "2026-10-13T14:30:00+07:00"
},
{
"name": "branch_name",
"type": "string",
"required": true,
"desc": "ชื่อสาขา",
"example": "อารีย์"
},
{
"name": "service_name",
"type": "string",
"required": true,
"desc": "บริการที่นัด",
"example": "ทรีตเมนต์เลเซอร์ผิวใส"
},
{
"name": "doctor_name",
"type": "string",
"required": false,
"desc": "แพทย์ผู้ดูแล",
"example": "พญ.กานต์ธิดา"
},
{
"name": "confirm_url",
"type": "url",
"required": true,
"desc": "ลิงก์ยืนยัน/เลื่อนนัด (https)",
"example": "https://phiwsai.example/a/0318"
}
],
"status": "published",
"current_version": 3,
"published_version": 3,
"draft_version": null,
"tags": [
"appointment"
],
"usage": {
"last_30d": 1322,
"last_sent_at": "2026-10-12T09:58:41+07:00"
},
"created_by": "usr_marketing_01",
"created_at": "2026-02-24T14:00:00+07:00",
"updated_at": "2026-09-02T11:30:00+07:00"
},
{
"id": "tpl_promo_october",
"object": "template",
"name": "โปรเดือนตุลา",
"description": "ใช้ได้ทุกช่องทาง — ระบบนัดเรียกอัตโนมัติ 10:00 ของวันก่อนนัด",
"category": "marketing",
"channels": [
"email",
"sms",
"push"
],
"locales": [
"th",
"en"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
}
],
"status": "published",
"current_version": 3,
"published_version": 3,
"draft_version": null,
"tags": [
"appointment"
],
"usage": {
"last_30d": 2940,
"last_sent_at": "2026-10-12T08:00:00+07:00"
},
"created_by": "usr_marketing_01",
"created_at": "2026-02-24T14:00:00+07:00",
"updated_at": "2026-09-02T11:30:00+07:00"
}
],
"has_more": true,
"next_cursor": "tpl_promo_october"
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#invalid_request"
}
}สร้างแม่แบบ
สร้างแม่แบบพร้อมเวอร์ชันแรก (draft) · sandbox ใช้ฉบับร่างส่งได้ทันที แต่ production ต้องเผยแพร่ก่อน
Request bodyapplication/json
idstringไม่บังคับรหัสที่อ่านง่าย (ไม่ระบุ = สุ่ม) a-z 0-9 _
namestringจำเป็นชื่อ
descriptionstringไม่บังคับคำอธิบาย
categorystringจำเป็นประเภท
channelsarray<string>จำเป็นช่องทางที่มีเนื้อหา
default_localestringไม่บังคับภาษาตั้งต้น
variablesarray<object>ไม่บังคับประกาศตัวแปร (ชนิดใช้ตรวจตอนส่ง)
ฟิลด์ย่อยของ
variables(5)namestringจำเป็นชื่อ a-z 0-9 _
typestringจำเป็นชนิด
requiredbooleanไม่บังคับบังคับหรือไม่
descstringไม่บังคับคำอธิบาย
examplestringไม่บังคับค่าตัวอย่าง (ใช้ตอนทดสอบ)
contentobjectไม่บังคับเนื้อหาต่อภาษา → ต่อช่องทาง (th / en)
ฟิลด์ย่อยของ
content(2)thobjectไม่บังคับภาษาไทย
ฟิลด์ย่อยของ
th(7)email_subjectstringไม่บังคับหัวเรื่องอีเมล
email_textstringไม่บังคับเนื้อหาอีเมล
smsstringไม่บังคับข้อความ SMS
line_titlestringไม่บังคับหัวข้อการ์ด LINE ≤ 40
line_bodystringไม่บังคับเนื้อหาการ์ด LINE
push_titlestringไม่บังคับหัวข้อ push
push_bodystringไม่บังคับเนื้อหา push
enobjectไม่บังคับภาษาอังกฤษ (ช่องเดียวกัน)
tagsarray<string>ไม่บังคับป้าย
ผลลัพธ์
- 201สร้างแล้ว (status = draft, version 1)
- 422
template_syntax_errorรูปแบบแม่แบบผิด - 400
invalid_requestคำขอไม่ถูกต้อง - 409
idempotency_conflictIdempotency-Key ซ้ำแต่เนื้อหาต่าง
- ระบบตรวจไวยากรณ์ทุกช่องตอนสร้าง — ตัวแปรที่ใช้ในเนื้อหาต้องประกาศใน variables
curl -X POST "https://sandbox.api.siang.example/v1/templates" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Siang-Version: 2026-08-01" \
-d '{
"id": "tpl_lab_result_ready",
"name": "แจ้งผลตรวจผิวพร้อมแล้ว",
"category": "transactional",
"channels": [
"line",
"sms"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "result_url",
"type": "url",
"required": true,
"desc": "ลิงก์ดูผล",
"example": "https://phiwsai.example/r/88"
}
],
"content": {
"th": {
"line_title": "ผลตรวจผิวพร้อมแล้ว",
"line_body": "คุณ{{customer_name}} ดูผลได้ที่ปุ่มด้านล่าง",
"sms": "ผิวใส คลินิก: ผลตรวจผิวของคุณ{{customer_name}} พร้อมแล้ว {{result_url}}"
}
},
"tags": [
"lab"
]
}'const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Siang-Version': '2026-08-01',
},
body: JSON.stringify({
"id": "tpl_lab_result_ready",
"name": "แจ้งผลตรวจผิวพร้อมแล้ว",
"category": "transactional",
"channels": [
"line",
"sms"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "result_url",
"type": "url",
"required": true,
"desc": "ลิงก์ดูผล",
"example": "https://phiwsai.example/r/88"
}
],
"content": {
"th": {
"line_title": "ผลตรวจผิวพร้อมแล้ว",
"line_body": "คุณ{{customer_name}} ดูผลได้ที่ปุ่มด้านล่าง",
"sms": "ผิวใส คลินิก: ผลตรวจผิวของคุณ{{customer_name}} พร้อมแล้ว {{result_url}}"
}
},
"tags": [
"lab"
]
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.post(
"https://sandbox.api.siang.example/v1/templates",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Siang-Version": "2026-08-01",
},
json={
"id": "tpl_lab_result_ready",
"name": "แจ้งผลตรวจผิวพร้อมแล้ว",
"category": "transactional",
"channels": [
"line",
"sms"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": True,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "result_url",
"type": "url",
"required": True,
"desc": "ลิงก์ดูผล",
"example": "https://phiwsai.example/r/88"
}
],
"content": {
"th": {
"line_title": "ผลตรวจผิวพร้อมแล้ว",
"line_body": "คุณ{{customer_name}} ดูผลได้ที่ปุ่มด้านล่าง",
"sms": "ผิวใส คลินิก: ผลตรวจผิวของคุณ{{customer_name}} พร้อมแล้ว {{result_url}}"
}
},
"tags": [
"lab"
]
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "tpl_lab_result_ready",
"object": "template",
"name": "แจ้งผลตรวจผิวพร้อมแล้ว",
"description": "ใช้ได้ทุกช่องทาง — ระบบนัดเรียกอัตโนมัติ 10:00 ของวันก่อนนัด",
"category": "transactional",
"channels": [
"line",
"sms"
],
"locales": [
"th",
"en"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "appointment_at",
"type": "datetime",
"required": true,
"desc": "วันเวลานัด ISO 8601",
"example": "2026-10-13T14:30:00+07:00"
},
{
"name": "branch_name",
"type": "string",
"required": true,
"desc": "ชื่อสาขา",
"example": "อารีย์"
},
{
"name": "service_name",
"type": "string",
"required": true,
"desc": "บริการที่นัด",
"example": "ทรีตเมนต์เลเซอร์ผิวใส"
},
{
"name": "doctor_name",
"type": "string",
"required": false,
"desc": "แพทย์ผู้ดูแล",
"example": "พญ.กานต์ธิดา"
},
{
"name": "confirm_url",
"type": "url",
"required": true,
"desc": "ลิงก์ยืนยัน/เลื่อนนัด (https)",
"example": "https://phiwsai.example/a/0318"
}
],
"status": "draft",
"current_version": 1,
"published_version": null,
"draft_version": 1,
"tags": [
"appointment"
],
"usage": {
"last_30d": 0,
"last_sent_at": null
},
"created_by": "usr_marketing_01",
"created_at": "2026-10-12T11:00:00+07:00",
"updated_at": "2026-10-12T11:00:00+07:00"
}{
"error": {
"code": "template_syntax_error",
"message": "รูปแบบแม่แบบผิด",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_syntax_error"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#invalid_request"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่เนื้อหาต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#idempotency_conflict"
}
}ดูแม่แบบ
GET/v1/templates/{template_id}
ข้อมูลแม่แบบ ตัวแปร เวอร์ชันที่เผยแพร่ และสถิติการใช้ 30 วัน · expand=published เพื่อดูเนื้อหา
Path parameterspath
template_idstringจำเป็นรหัสแม่แบบ
Query parametersquery
expandarray<string>ไม่บังคับขยาย
ผลลัพธ์
- 200แม่แบบ
- 404
template_not_foundไม่พบแม่แบบ
curl -X GET "https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Siang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Siang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.get(
"https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder",
headers={
"Authorization": f"Bearer {API_KEY}",
"Siang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "tpl_appointment_reminder",
"object": "template",
"name": "เตือนนัดล่วงหน้า 1 วัน",
"description": "ใช้ได้ทุกช่องทาง — ระบบนัดเรียกอัตโนมัติ 10:00 ของวันก่อนนัด",
"category": "transactional",
"channels": [
"email",
"sms",
"line",
"push"
],
"locales": [
"th",
"en"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "appointment_at",
"type": "datetime",
"required": true,
"desc": "วันเวลานัด ISO 8601",
"example": "2026-10-13T14:30:00+07:00"
},
{
"name": "branch_name",
"type": "string",
"required": true,
"desc": "ชื่อสาขา",
"example": "อารีย์"
},
{
"name": "service_name",
"type": "string",
"required": true,
"desc": "บริการที่นัด",
"example": "ทรีตเมนต์เลเซอร์ผิวใส"
},
{
"name": "doctor_name",
"type": "string",
"required": false,
"desc": "แพทย์ผู้ดูแล",
"example": "พญ.กานต์ธิดา"
},
{
"name": "confirm_url",
"type": "url",
"required": true,
"desc": "ลิงก์ยืนยัน/เลื่อนนัด (https)",
"example": "https://phiwsai.example/a/0318"
}
],
"status": "published",
"current_version": 3,
"published_version": 3,
"draft_version": null,
"tags": [
"appointment"
],
"usage": {
"last_30d": 4180,
"last_sent_at": "2026-10-12T10:00:00+07:00"
},
"created_by": "usr_marketing_01",
"created_at": "2026-02-24T14:00:00+07:00",
"updated_at": "2026-09-02T11:30:00+07:00"
}{
"error": {
"code": "template_not_found",
"message": "ไม่พบแม่แบบ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_found"
}
}แก้ข้อมูลแม่แบบ
PATCH/v1/templates/{template_id}
แก้ชื่อ คำอธิบาย ป้าย ภาษาตั้งต้น (ไม่แก้เนื้อหา — เนื้อหาเปลี่ยนผ่านเวอร์ชันใหม่เท่านั้นเพื่อให้ตรวจย้อนได้)
Path parameterspath
template_idstringจำเป็นรหัสแม่แบบ
Request bodyapplication/json
namestringไม่บังคับชื่อ
descriptionstringไม่บังคับคำอธิบาย
tagsarray<string>ไม่บังคับป้าย
default_localestringไม่บังคับภาษาตั้งต้น
ผลลัพธ์
- 200แก้แล้ว
- 404
template_not_foundไม่พบแม่แบบ - 400
invalid_requestคำขอไม่ถูกต้อง
curl -X PATCH "https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Content-Type: application/json" \
-H "Siang-Version: 2026-08-01" \
-d '{
"name": "เตือนนัดล่วงหน้า 1 วัน (ทุกช่องทาง)",
"description": "",
"tags": [
"appointment",
"auto"
],
"default_locale": "th"
}'const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder', {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Siang-Version': '2026-08-01',
},
body: JSON.stringify({
"name": "เตือนนัดล่วงหน้า 1 วัน (ทุกช่องทาง)",
"description": "",
"tags": [
"appointment",
"auto"
],
"default_locale": "th"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.patch(
"https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Siang-Version": "2026-08-01",
},
json={
"name": "เตือนนัดล่วงหน้า 1 วัน (ทุกช่องทาง)",
"description": "",
"tags": [
"appointment",
"auto"
],
"default_locale": "th"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "tpl_appointment_reminder",
"object": "template",
"name": "เตือนนัดล่วงหน้า 1 วัน (ทุกช่องทาง)",
"description": "ใช้ได้ทุกช่องทาง — ระบบนัดเรียกอัตโนมัติ 10:00 ของวันก่อนนัด",
"category": "transactional",
"channels": [
"email",
"sms",
"line",
"push"
],
"locales": [
"th",
"en"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "appointment_at",
"type": "datetime",
"required": true,
"desc": "วันเวลานัด ISO 8601",
"example": "2026-10-13T14:30:00+07:00"
},
{
"name": "branch_name",
"type": "string",
"required": true,
"desc": "ชื่อสาขา",
"example": "อารีย์"
},
{
"name": "service_name",
"type": "string",
"required": true,
"desc": "บริการที่นัด",
"example": "ทรีตเมนต์เลเซอร์ผิวใส"
},
{
"name": "doctor_name",
"type": "string",
"required": false,
"desc": "แพทย์ผู้ดูแล",
"example": "พญ.กานต์ธิดา"
},
{
"name": "confirm_url",
"type": "url",
"required": true,
"desc": "ลิงก์ยืนยัน/เลื่อนนัด (https)",
"example": "https://phiwsai.example/a/0318"
}
],
"status": "published",
"current_version": 3,
"published_version": 3,
"draft_version": null,
"tags": [
"appointment",
"auto"
],
"usage": {
"last_30d": 4180,
"last_sent_at": "2026-10-12T10:00:00+07:00"
},
"created_by": "usr_marketing_01",
"created_at": "2026-02-24T14:00:00+07:00",
"updated_at": "2026-10-12T11:02:00+07:00"
}{
"error": {
"code": "template_not_found",
"message": "ไม่พบแม่แบบ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_found"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#invalid_request"
}
}สร้างเวอร์ชันใหม่ (ฉบับร่าง)
POST/v1/templates/{template_id}/versions
เริ่มแก้เนื้อหาจากเวอร์ชันล่าสุด — ส่ง base_version กันการแก้ทับกัน (optimistic locking)
Path parameterspath
template_idstringจำเป็นรหัสแม่แบบ
Request bodyapplication/json
base_versionintegerจำเป็นเวอร์ชันที่แก้ต่อจาก
contentobjectไม่บังคับเนื้อหาต่อภาษา → ต่อช่องทาง (th / en)
ฟิลด์ย่อยของ
content(2)thobjectไม่บังคับภาษาไทย
ฟิลด์ย่อยของ
th(7)email_subjectstringไม่บังคับหัวเรื่องอีเมล
email_textstringไม่บังคับเนื้อหาอีเมล
smsstringไม่บังคับข้อความ SMS
line_titlestringไม่บังคับหัวข้อการ์ด LINE ≤ 40
line_bodystringไม่บังคับเนื้อหาการ์ด LINE
push_titlestringไม่บังคับหัวข้อ push
push_bodystringไม่บังคับเนื้อหา push
enobjectไม่บังคับภาษาอังกฤษ (ช่องเดียวกัน)
variablesarray<object>ไม่บังคับประกาศตัวแปร (ชนิดใช้ตรวจตอนส่ง)
ฟิลด์ย่อยของ
variables(5)namestringจำเป็นชื่อ a-z 0-9 _
typestringจำเป็นชนิด
requiredbooleanไม่บังคับบังคับหรือไม่
descstringไม่บังคับคำอธิบาย
examplestringไม่บังคับค่าตัวอย่าง (ใช้ตอนทดสอบ)
change_notestringจำเป็นสรุปสิ่งที่เปลี่ยน (แสดงให้ผู้อนุมัติ)
ผลลัพธ์
- 201ฉบับร่างใหม่
- 409
version_conflictเวอร์ชันชนกัน - 422
template_syntax_errorรูปแบบแม่แบบผิด - 404
template_not_foundไม่พบแม่แบบ
curl -X POST "https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Siang-Version: 2026-08-01" \
-d '{
"base_version": 3,
"content": {
"th": {
"email_subject": "เตือนนัด {{service_name}} {{appointment_at|date}}",
"email_text": "สวัสดีค่ะ คุณ{{customer_name}}\n\nผิวใส คลินิก ขอเตือนนัดของคุณ\nบริการ: {{service_name}}\nวันเวลา: {{appointment_at|datetime}}\nสาขา: {{branch_name}}\nแพทย์: {{doctor_name|default:\"แพทย์ประจำสาขา\"}}\n\nยืนยันหรือขอเลื่อนนัด: {{confirm_url}}",
"sms": "ผิวใส คลินิก: เตือนนัดคุณ{{customer_name}} {{appointment_at|date}} {{appointment_at|time}} สาขา{{branch_name}} ยืนยัน/เลื่อน {{confirm_url}} มาก่อน 15 นาที",
"line_title": "พรุ่งนี้มีนัดที่ผิวใส คลินิก",
"line_body": "คุณ{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\nสาขา{{branch_name}} · {{doctor_name|default:\"แพทย์ประจำสาขา\"}}",
"push_title": "วันนี้ {{appointment_at|time}} นัด{{service_name}}",
"push_body": "สาขา{{branch_name}} กับ{{doctor_name|default:\"แพทย์ประจำสาขา\"}} · แตะเพื่อยืนยันหรือเลื่อนนัด"
},
"en": {
"email_subject": "Reminder: {{service_name}} on {{appointment_at|date}}",
"email_text": "Hi {{customer_name}},\n\nThis is a reminder of your appointment at PhiwSai Clinic.\nService: {{service_name}}\nWhen: {{appointment_at|datetime}}\nBranch: {{branch_name}}\nDoctor: {{doctor_name|default:\"on-duty doctor\"}}\n\nConfirm or reschedule: {{confirm_url}}",
"sms": "PhiwSai Clinic: {{customer_name}}, your appointment is {{appointment_at|date}} {{appointment_at|time}} at {{branch_name}}. Confirm: {{confirm_url}}",
"line_title": "Your appointment is tomorrow",
"line_body": "{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\n{{branch_name}} · {{doctor_name|default:\"on-duty doctor\"}}",
"push_title": "Today {{appointment_at|time}}: {{service_name}}",
"push_body": "{{branch_name}} with {{doctor_name|default:\"on-duty doctor\"}} · tap to confirm"
}
},
"change_note": "เพิ่มบรรทัด “กรุณามาก่อนเวลา 15 นาที” ทุกช่องทาง"
}'const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Siang-Version': '2026-08-01',
},
body: JSON.stringify({
"base_version": 3,
"content": {
"th": {
"email_subject": "เตือนนัด {{service_name}} {{appointment_at|date}}",
"email_text": "สวัสดีค่ะ คุณ{{customer_name}}\n\nผิวใส คลินิก ขอเตือนนัดของคุณ\nบริการ: {{service_name}}\nวันเวลา: {{appointment_at|datetime}}\nสาขา: {{branch_name}}\nแพทย์: {{doctor_name|default:\"แพทย์ประจำสาขา\"}}\n\nยืนยันหรือขอเลื่อนนัด: {{confirm_url}}",
"sms": "ผิวใส คลินิก: เตือนนัดคุณ{{customer_name}} {{appointment_at|date}} {{appointment_at|time}} สาขา{{branch_name}} ยืนยัน/เลื่อน {{confirm_url}} มาก่อน 15 นาที",
"line_title": "พรุ่งนี้มีนัดที่ผิวใส คลินิก",
"line_body": "คุณ{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\nสาขา{{branch_name}} · {{doctor_name|default:\"แพทย์ประจำสาขา\"}}",
"push_title": "วันนี้ {{appointment_at|time}} นัด{{service_name}}",
"push_body": "สาขา{{branch_name}} กับ{{doctor_name|default:\"แพทย์ประจำสาขา\"}} · แตะเพื่อยืนยันหรือเลื่อนนัด"
},
"en": {
"email_subject": "Reminder: {{service_name}} on {{appointment_at|date}}",
"email_text": "Hi {{customer_name}},\n\nThis is a reminder of your appointment at PhiwSai Clinic.\nService: {{service_name}}\nWhen: {{appointment_at|datetime}}\nBranch: {{branch_name}}\nDoctor: {{doctor_name|default:\"on-duty doctor\"}}\n\nConfirm or reschedule: {{confirm_url}}",
"sms": "PhiwSai Clinic: {{customer_name}}, your appointment is {{appointment_at|date}} {{appointment_at|time}} at {{branch_name}}. Confirm: {{confirm_url}}",
"line_title": "Your appointment is tomorrow",
"line_body": "{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\n{{branch_name}} · {{doctor_name|default:\"on-duty doctor\"}}",
"push_title": "Today {{appointment_at|time}}: {{service_name}}",
"push_body": "{{branch_name}} with {{doctor_name|default:\"on-duty doctor\"}} · tap to confirm"
}
},
"change_note": "เพิ่มบรรทัด “กรุณามาก่อนเวลา 15 นาที” ทุกช่องทาง"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.post(
"https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Siang-Version": "2026-08-01",
},
json={
"base_version": 3,
"content": {
"th": {
"email_subject": "เตือนนัด {{service_name}} {{appointment_at|date}}",
"email_text": "สวัสดีค่ะ คุณ{{customer_name}}\n\nผิวใส คลินิก ขอเตือนนัดของคุณ\nบริการ: {{service_name}}\nวันเวลา: {{appointment_at|datetime}}\nสาขา: {{branch_name}}\nแพทย์: {{doctor_name|default:\"แพทย์ประจำสาขา\"}}\n\nยืนยันหรือขอเลื่อนนัด: {{confirm_url}}",
"sms": "ผิวใส คลินิก: เตือนนัดคุณ{{customer_name}} {{appointment_at|date}} {{appointment_at|time}} สาขา{{branch_name}} ยืนยัน/เลื่อน {{confirm_url}} มาก่อน 15 นาที",
"line_title": "พรุ่งนี้มีนัดที่ผิวใส คลินิก",
"line_body": "คุณ{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\nสาขา{{branch_name}} · {{doctor_name|default:\"แพทย์ประจำสาขา\"}}",
"push_title": "วันนี้ {{appointment_at|time}} นัด{{service_name}}",
"push_body": "สาขา{{branch_name}} กับ{{doctor_name|default:\"แพทย์ประจำสาขา\"}} · แตะเพื่อยืนยันหรือเลื่อนนัด"
},
"en": {
"email_subject": "Reminder: {{service_name}} on {{appointment_at|date}}",
"email_text": "Hi {{customer_name}},\n\nThis is a reminder of your appointment at PhiwSai Clinic.\nService: {{service_name}}\nWhen: {{appointment_at|datetime}}\nBranch: {{branch_name}}\nDoctor: {{doctor_name|default:\"on-duty doctor\"}}\n\nConfirm or reschedule: {{confirm_url}}",
"sms": "PhiwSai Clinic: {{customer_name}}, your appointment is {{appointment_at|date}} {{appointment_at|time}} at {{branch_name}}. Confirm: {{confirm_url}}",
"line_title": "Your appointment is tomorrow",
"line_body": "{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\n{{branch_name}} · {{doctor_name|default:\"on-duty doctor\"}}",
"push_title": "Today {{appointment_at|time}}: {{service_name}}",
"push_body": "{{branch_name}} with {{doctor_name|default:\"on-duty doctor\"}} · tap to confirm"
}
},
"change_note": "เพิ่มบรรทัด “กรุณามาก่อนเวลา 15 นาที” ทุกช่องทาง"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "tplv_4",
"object": "template_version",
"template_id": "tpl_appointment_reminder",
"version": 4,
"status": "draft",
"content": {
"th": {
"email_subject": "เตือนนัด {{service_name}} {{appointment_at|date}}",
"email_text": "สวัสดีค่ะ คุณ{{customer_name}}\n\nผิวใส คลินิก ขอเตือนนัดของคุณ\nบริการ: {{service_name}}\nวันเวลา: {{appointment_at|datetime}}\nสาขา: {{branch_name}}\nแพทย์: {{doctor_name|default:\"แพทย์ประจำสาขา\"}}\n\nยืนยันหรือขอเลื่อนนัด: {{confirm_url}}",
"sms": "ผิวใส คลินิก: เตือนนัดคุณ{{customer_name}} {{appointment_at|date}} {{appointment_at|time}} สาขา{{branch_name}} ยืนยัน/เลื่อน {{confirm_url}} มาก่อน 15 นาที",
"line_title": "พรุ่งนี้มีนัดที่ผิวใส คลินิก",
"line_body": "คุณ{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\nสาขา{{branch_name}} · {{doctor_name|default:\"แพทย์ประจำสาขา\"}}",
"push_title": "วันนี้ {{appointment_at|time}} นัด{{service_name}}",
"push_body": "สาขา{{branch_name}} กับ{{doctor_name|default:\"แพทย์ประจำสาขา\"}} · แตะเพื่อยืนยันหรือเลื่อนนัด"
},
"en": {
"email_subject": "Reminder: {{service_name}} on {{appointment_at|date}}",
"email_text": "Hi {{customer_name}},\n\nThis is a reminder of your appointment at PhiwSai Clinic.\nService: {{service_name}}\nWhen: {{appointment_at|datetime}}\nBranch: {{branch_name}}\nDoctor: {{doctor_name|default:\"on-duty doctor\"}}\n\nConfirm or reschedule: {{confirm_url}}",
"sms": "PhiwSai Clinic: {{customer_name}}, your appointment is {{appointment_at|date}} {{appointment_at|time}} at {{branch_name}}. Confirm: {{confirm_url}}",
"line_title": "Your appointment is tomorrow",
"line_body": "{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\n{{branch_name}} · {{doctor_name|default:\"on-duty doctor\"}}",
"push_title": "Today {{appointment_at|time}}: {{service_name}}",
"push_body": "{{branch_name}} with {{doctor_name|default:\"on-duty doctor\"}} · tap to confirm"
}
},
"change_note": "เพิ่มบรรทัด “กรุณามาก่อนเวลา 15 นาที” ทุกช่องทาง",
"submitted_by": null,
"submitted_at": null,
"approved_by": null,
"approved_at": null,
"published_at": null,
"created_at": "2026-10-12T11:05:00+07:00"
}{
"error": {
"code": "version_conflict",
"message": "เวอร์ชันชนกัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#version_conflict"
}
}{
"error": {
"code": "template_syntax_error",
"message": "รูปแบบแม่แบบผิด",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_syntax_error"
}
}{
"error": {
"code": "template_not_found",
"message": "ไม่พบแม่แบบ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_found"
}
}ประวัติเวอร์ชัน
GET/v1/templates/{template_id}/versions
ทุกเวอร์ชันพร้อมผู้ส่งตรวจ ผู้อนุมัติ และเวลา — ใช้ตรวจย้อนหลังว่าข้อความที่ลูกค้าได้ ณ วันใดเป็นฉบับไหน
Path parameterspath
template_idstringจำเป็นรหัสแม่แบบ
Query parametersquery
limitintegerไม่บังคับจำนวนต่อหน้า
starting_afterstringไม่บังคับcursor — รหัสรายการสุดท้ายของหน้าก่อน (ใช้ค่า next_cursor)
ending_beforestringไม่บังคับcursor ย้อนกลับ — รหัสรายการแรกของหน้าปัจจุบัน
statusstringไม่บังคับสถานะ
ผลลัพธ์
- 200รายการเวอร์ชัน
- 404
template_not_foundไม่พบแม่แบบ
curl -X GET "https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions?limit=20" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Siang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions?limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Siang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.get(
"https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions?limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Siang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v1/templates/tpl_appointment_reminder/versions",
"data": [
{
"id": "tplv_4",
"object": "template_version",
"template_id": "tpl_appointment_reminder",
"version": 4,
"status": "draft",
"change_note": "เพิ่มบรรทัด “กรุณามาก่อนเวลา 15 นาที” ทุกช่องทาง",
"submitted_by": null,
"submitted_at": null,
"approved_by": null,
"approved_at": null,
"published_at": null,
"created_at": "2026-10-12T11:05:00+07:00"
},
{
"id": "tplv_3",
"object": "template_version",
"template_id": "tpl_appointment_reminder",
"version": 3,
"status": "published",
"change_note": "เพิ่มชื่อแพทย์ (doctor_name ไม่บังคับ มีค่าตั้งต้น) และลิงก์ยืนยัน/เลื่อนนัด",
"submitted_by": "usr_marketing_01",
"submitted_at": "2026-09-01T16:20:00+07:00",
"approved_by": "usr_manager_02",
"approved_at": "2026-09-02T11:25:00+07:00",
"published_at": "2026-09-02T11:30:00+07:00",
"created_at": "2026-09-01T15:02:00+07:00"
},
{
"id": "tplv_2",
"object": "template_version",
"template_id": "tpl_appointment_reminder",
"version": 2,
"status": "superseded",
"change_note": "เพิ่มภาษาอังกฤษ",
"submitted_by": "usr_marketing_01",
"submitted_at": "2026-09-01T16:20:00+07:00",
"approved_by": "usr_manager_02",
"approved_at": "2026-09-02T11:25:00+07:00",
"published_at": "2026-04-11T10:00:00+07:00",
"created_at": "2026-09-01T15:02:00+07:00"
}
],
"has_more": false,
"next_cursor": null
}{
"error": {
"code": "template_not_found",
"message": "ไม่พบแม่แบบ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_found"
}
}ส่งตรวจ / อนุมัติ / ไม่อนุมัติ
POST/v1/templates/{template_id}/versions/{version}/review
ขั้นอนุมัติ 2 คน: ผู้แก้ส่งตรวจ (action=submit) → ผู้มี scope templates:approve อนุมัติหรือส่งกลับ (approve / reject) · ผู้แก้อนุมัติงานตัวเองไม่ได้
Path parameterspath
template_idstringจำเป็นรหัสแม่แบบ
versionintegerจำเป็นเวอร์ชัน
Request bodyapplication/json
actionstringจำเป็นการกระทำ
commentstringไม่บังคับความเห็น (reject บังคับ)
ผลลัพธ์
- 200สถานะใหม่ของเวอร์ชัน
- 403
insufficient_scopeสิทธิ์ของ key ไม่พอ - 409
version_conflictเวอร์ชันชนกัน - 404
template_not_foundไม่พบแม่แบบ
curl -X POST "https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions/4/review" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Content-Type: application/json" \
-H "Siang-Version: 2026-08-01" \
-d '{
"action": "approve",
"comment": "ข้อความ SMS ยังไม่เกิน 2 segment ผ่าน"
}'const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions/4/review', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Siang-Version': '2026-08-01',
},
body: JSON.stringify({
"action": "approve",
"comment": "ข้อความ SMS ยังไม่เกิน 2 segment ผ่าน"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.post(
"https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/versions/4/review",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Siang-Version": "2026-08-01",
},
json={
"action": "approve",
"comment": "ข้อความ SMS ยังไม่เกิน 2 segment ผ่าน"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "tplv_4",
"object": "template_version",
"template_id": "tpl_appointment_reminder",
"version": 4,
"status": "approved",
"content": {
"th": {
"email_subject": "เตือนนัด {{service_name}} {{appointment_at|date}}",
"email_text": "สวัสดีค่ะ คุณ{{customer_name}}\n\nผิวใส คลินิก ขอเตือนนัดของคุณ\nบริการ: {{service_name}}\nวันเวลา: {{appointment_at|datetime}}\nสาขา: {{branch_name}}\nแพทย์: {{doctor_name|default:\"แพทย์ประจำสาขา\"}}\n\nยืนยันหรือขอเลื่อนนัด: {{confirm_url}}",
"sms": "ผิวใส คลินิก: เตือนนัดคุณ{{customer_name}} {{appointment_at|date}} {{appointment_at|time}} สาขา{{branch_name}} ยืนยัน/เลื่อน {{confirm_url}} มาก่อน 15 นาที",
"line_title": "พรุ่งนี้มีนัดที่ผิวใส คลินิก",
"line_body": "คุณ{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\nสาขา{{branch_name}} · {{doctor_name|default:\"แพทย์ประจำสาขา\"}}",
"push_title": "วันนี้ {{appointment_at|time}} นัด{{service_name}}",
"push_body": "สาขา{{branch_name}} กับ{{doctor_name|default:\"แพทย์ประจำสาขา\"}} · แตะเพื่อยืนยันหรือเลื่อนนัด"
},
"en": {
"email_subject": "Reminder: {{service_name}} on {{appointment_at|date}}",
"email_text": "Hi {{customer_name}},\n\nThis is a reminder of your appointment at PhiwSai Clinic.\nService: {{service_name}}\nWhen: {{appointment_at|datetime}}\nBranch: {{branch_name}}\nDoctor: {{doctor_name|default:\"on-duty doctor\"}}\n\nConfirm or reschedule: {{confirm_url}}",
"sms": "PhiwSai Clinic: {{customer_name}}, your appointment is {{appointment_at|date}} {{appointment_at|time}} at {{branch_name}}. Confirm: {{confirm_url}}",
"line_title": "Your appointment is tomorrow",
"line_body": "{{customer_name}} · {{service_name}}\n{{appointment_at|datetime}}\n{{branch_name}} · {{doctor_name|default:\"on-duty doctor\"}}",
"push_title": "Today {{appointment_at|time}}: {{service_name}}",
"push_body": "{{branch_name}} with {{doctor_name|default:\"on-duty doctor\"}} · tap to confirm"
}
},
"change_note": "เพิ่มบรรทัด “กรุณามาก่อนเวลา 15 นาที” ทุกช่องทาง",
"submitted_by": "usr_marketing_01",
"submitted_at": "2026-10-12T11:20:00+07:00",
"approved_by": "usr_manager_02",
"approved_at": "2026-10-12T13:05:00+07:00",
"published_at": null,
"created_at": "2026-10-12T11:05:00+07:00"
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ของ key ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#insufficient_scope"
}
}{
"error": {
"code": "version_conflict",
"message": "เวอร์ชันชนกัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#version_conflict"
}
}{
"error": {
"code": "template_not_found",
"message": "ไม่พบแม่แบบ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_found"
}
}เผยแพร่เวอร์ชัน
POST/v1/templates/{template_id}/publish
ให้เวอร์ชันที่อนุมัติแล้วเป็นฉบับที่ใช้ส่งจริง (ข้อความที่อยู่ในคิว/ตั้งเวลาไว้แล้วยังใช้ฉบับเดิม) · ย้อนกลับได้โดยเผยแพร่เวอร์ชันเก่า
Path parameterspath
template_idstringจำเป็นรหัสแม่แบบ
Request bodyapplication/json
versionintegerจำเป็นเวอร์ชันที่อนุมัติแล้ว
ผลลัพธ์
- 200เผยแพร่แล้ว
- 409
template_not_publishedแม่แบบยังไม่เผยแพร่ - 409
version_conflictเวอร์ชันชนกัน - 404
template_not_foundไม่พบแม่แบบ
curl -X POST "https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/publish" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Siang-Version: 2026-08-01" \
-d '{
"version": 4
}'const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/publish', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Siang-Version': '2026-08-01',
},
body: JSON.stringify({
"version": 4
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.post(
"https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/publish",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Siang-Version": "2026-08-01",
},
json={
"version": 4
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "tpl_appointment_reminder",
"object": "template",
"name": "เตือนนัดล่วงหน้า 1 วัน",
"description": "ใช้ได้ทุกช่องทาง — ระบบนัดเรียกอัตโนมัติ 10:00 ของวันก่อนนัด",
"category": "transactional",
"channels": [
"email",
"sms",
"line",
"push"
],
"locales": [
"th",
"en"
],
"default_locale": "th",
"variables": [
{
"name": "customer_name",
"type": "string",
"required": true,
"desc": "ชื่อลูกค้า (ชื่อเล่นหรือชื่อจริง)",
"example": "ศิริพร"
},
{
"name": "appointment_at",
"type": "datetime",
"required": true,
"desc": "วันเวลานัด ISO 8601",
"example": "2026-10-13T14:30:00+07:00"
},
{
"name": "branch_name",
"type": "string",
"required": true,
"desc": "ชื่อสาขา",
"example": "อารีย์"
},
{
"name": "service_name",
"type": "string",
"required": true,
"desc": "บริการที่นัด",
"example": "ทรีตเมนต์เลเซอร์ผิวใส"
},
{
"name": "doctor_name",
"type": "string",
"required": false,
"desc": "แพทย์ผู้ดูแล",
"example": "พญ.กานต์ธิดา"
},
{
"name": "confirm_url",
"type": "url",
"required": true,
"desc": "ลิงก์ยืนยัน/เลื่อนนัด (https)",
"example": "https://phiwsai.example/a/0318"
}
],
"status": "published",
"current_version": 4,
"published_version": 4,
"draft_version": null,
"tags": [
"appointment"
],
"usage": {
"last_30d": 4180,
"last_sent_at": "2026-10-12T10:00:00+07:00"
},
"created_by": "usr_marketing_01",
"created_at": "2026-02-24T14:00:00+07:00",
"updated_at": "2026-10-12T13:06:00+07:00"
}{
"error": {
"code": "template_not_published",
"message": "แม่แบบยังไม่เผยแพร่",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_published"
}
}{
"error": {
"code": "version_conflict",
"message": "เวอร์ชันชนกัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#version_conflict"
}
}{
"error": {
"code": "template_not_found",
"message": "ไม่พบแม่แบบ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_found"
}
}ทดสอบแสดงผล
POST/v1/templates/{template_id}/render
แทนค่าตัวแปรแล้วคืนผลทุกช่องทาง (ไม่ส่งจริง ไม่คิดเงิน) พร้อมจำนวน segment ของ SMS และ error รายตัวแปร — ใช้ก่อนเผยแพร่หรือแสดงตัวอย่างในหลังบ้าน
Path parameterspath
template_idstringจำเป็นรหัสแม่แบบ
Request bodyapplication/json
versionintegerไม่บังคับเวอร์ชัน (ไม่ระบุ = ที่เผยแพร่)
localestringไม่บังคับภาษา
channelsarray<string>ไม่บังคับช่องทาง (ไม่ระบุ = ทุกช่อง)
variablesobjectจำเป็นค่าตัวแปร
ผลลัพธ์
- 200ผลแสดงผล
- 422ตัวแปรขาด/ชนิดผิด — แสดงทุกจุด
- 422
variable_missingตัวแปรในแม่แบบขาด - 422
variable_type_mismatchชนิดตัวแปรไม่ตรง - 422
template_syntax_errorรูปแบบแม่แบบผิด - 404
template_not_foundไม่พบแม่แบบ
- ภาษาอังกฤษ (locale=en) ของตัวอย่างเดียวกัน: SMS “PhiwSai Clinic: Siriporn, your appointment is Tue 13 Oct 2026 14:30 at Ari. Confirm: https://phiwsai.example/a/0318”
curl -X POST "https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/render" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Content-Type: application/json" \
-H "Siang-Version: 2026-08-01" \
-d '{
"version": 3,
"locale": "th",
"variables": {
"customer_name": "ศิริพร",
"appointment_at": "2026-10-13T14:30:00+07:00",
"branch_name": "อารีย์",
"service_name": "ทรีตเมนต์เลเซอร์ผิวใส",
"doctor_name": "พญ.กานต์ธิดา",
"confirm_url": "https://phiwsai.example/a/0318"
}
}'const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/render', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Siang-Version': '2026-08-01',
},
body: JSON.stringify({
"version": 3,
"locale": "th",
"variables": {
"customer_name": "ศิริพร",
"appointment_at": "2026-10-13T14:30:00+07:00",
"branch_name": "อารีย์",
"service_name": "ทรีตเมนต์เลเซอร์ผิวใส",
"doctor_name": "พญ.กานต์ธิดา",
"confirm_url": "https://phiwsai.example/a/0318"
}
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.post(
"https://sandbox.api.siang.example/v1/templates/tpl_appointment_reminder/render",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Siang-Version": "2026-08-01",
},
json={
"version": 3,
"locale": "th",
"variables": {
"customer_name": "ศิริพร",
"appointment_at": "2026-10-13T14:30:00+07:00",
"branch_name": "อารีย์",
"service_name": "ทรีตเมนต์เลเซอร์ผิวใส",
"doctor_name": "พญ.กานต์ธิดา",
"confirm_url": "https://phiwsai.example/a/0318"
}
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"template_id": "tpl_appointment_reminder",
"version": 3,
"locale": "th",
"rendered": {
"email": {
"subject": "เตือนนัด ทรีตเมนต์เลเซอร์ผิวใส อ. 13 ต.ค. 2569",
"text": "สวัสดีค่ะ คุณศิริพร\n\nผิวใส คลินิก ขอเตือนนัดของคุณ\nบริการ: ทรีตเมนต์เลเซอร์ผิวใส\nวันเวลา: อ. 13 ต.ค. 2569 14:30 น.\nสาขา: อารีย์\nแพทย์: พญ.กานต์ธิดา\n\nยืนยันหรือขอเลื่อนนัด: https://phiwsai.example/a/0318"
},
"sms": {
"text": "ผิวใส คลินิก: เตือนนัดคุณศิริพร อ. 13 ต.ค. 2569 14:30 น. สาขาอารีย์ ยืนยัน/เลื่อน https://phiwsai.example/a/0318",
"encoding": "UCS-2",
"chars": 112,
"segments": 2
},
"line": {
"title": "พรุ่งนี้มีนัดที่ผิวใส คลินิก",
"body": "คุณศิริพร · ทรีตเมนต์เลเซอร์ผิวใส\nอ. 13 ต.ค. 2569 14:30 น.\nสาขาอารีย์ · พญ.กานต์ธิดา"
},
"push": {
"title": "วันนี้ 14:30 น. นัดทรีตเมนต์เลเซอร์ผิวใส",
"body": "สาขาอารีย์ กับพญ.กานต์ธิดา · แตะเพื่อยืนยันหรือเลื่อนนัด"
}
},
"warnings": []
}{
"error": {
"code": "variable_missing",
"message": "ขาดตัวแปร confirm_url",
"details": [
{
"code": "variable_missing",
"variable": "confirm_url",
"channels": [
"email",
"sms"
]
},
{
"code": "variable_type_mismatch",
"variable": "appointment_at",
"message": "ต้องเป็นเวลา ISO 8601"
}
],
"request_id": "req_6Rm1TzE5"
}
}{
"error": {
"code": "variable_missing",
"message": "ตัวแปรในแม่แบบขาด",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#variable_missing"
}
}{
"error": {
"code": "variable_type_mismatch",
"message": "ชนิดตัวแปรไม่ตรง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#variable_type_mismatch"
}
}{
"error": {
"code": "template_syntax_error",
"message": "รูปแบบแม่แบบผิด",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_syntax_error"
}
}{
"error": {
"code": "template_not_found",
"message": "ไม่พบแม่แบบ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_found"
}
}ลบ/เก็บถาวรแม่แบบ
DELETE/v1/templates/{template_id}
ลบแม่แบบที่ไม่เคยใช้ส่ง หรือเก็บถาวร (archive) ถ้าเคยใช้ — ประวัติข้อความยังอ้างถึงเวอร์ชันเดิมได้
Path parameterspath
template_idstringจำเป็นรหัสแม่แบบ
Query parametersquery
modestringไม่บังคับวิธีลบ
ผลลัพธ์
- 200เก็บถาวรแล้ว
- 409
template_in_useแม่แบบถูกใช้งานอยู่ - 404
template_not_foundไม่พบแม่แบบ
curl -X DELETE "https://sandbox.api.siang.example/v1/templates/tpl_promo_september" \
-H "Authorization: Bearer sg_test_4Rk8Lm2QpZ7vT1" \
-H "Siang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // sg_test_4Rk8Lm2QpZ7vT1
const res = await fetch('https://sandbox.api.siang.example/v1/templates/tpl_promo_september', {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Siang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # sg_test_4Rk8Lm2QpZ7vT1
res = requests.delete(
"https://sandbox.api.siang.example/v1/templates/tpl_promo_september",
headers={
"Authorization": f"Bearer {API_KEY}",
"Siang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "tpl_promo_september",
"object": "template",
"status": "archived",
"archived_at": "2026-10-12T11:40:00+07:00"
}{
"error": {
"code": "template_in_use",
"message": "แม่แบบถูกใช้งานอยู่",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_in_use"
}
}{
"error": {
"code": "template_not_found",
"message": "ไม่พบแม่แบบ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#template_not_found"
}
}Webhooks — แจ้งเหตุการณ์ไปที่ระบบของคุณ
ลงทะเบียน URL ปลายทาง แล้วระบบจะส่ง POST พร้อม JSON ทุกครั้งที่เกิดเหตุการณ์ด้านล่าง · ตอบกลับ 2xx ภายใน 10 วินาที ไม่งั้นจะส่งซ้ำตามตาราง · ทุกคำขอมีหัว Siang-Signature ให้ตรวจว่ามาจากเราจริง · event อาจมาซ้ำหรือสลับลำดับ ให้ใช้ id กันประมวลผลซ้ำ
template.version.submittedมีเวอร์ชันรออนุมัติ
ส่งเมื่อ: review action=submit
{
"id": "evt_01JB7Q00",
"type": "template.version.submitted",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"template_id": "tpl_appointment_reminder",
"version": 4,
"change_note": "เพิ่มบรรทัด “กรุณามาก่อนเวลา 15 นาที” ทุกช่องทาง",
"submitted_by": "usr_marketing_01",
"submitted_at": "2026-10-12T11:20:00+07:00"
}
}template.version.approvedอนุมัติแล้ว
ส่งเมื่อ: review action=approve
{
"id": "evt_01JB7Q01",
"type": "template.version.approved",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"template_id": "tpl_appointment_reminder",
"version": 4,
"approved_by": "usr_manager_02",
"approved_at": "2026-10-12T13:05:00+07:00"
}
}template.version.rejectedไม่อนุมัติ
ส่งเมื่อ: review action=reject
{
"id": "evt_01JB7Q02",
"type": "template.version.rejected",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"template_id": "tpl_appointment_reminder",
"version": 4,
"comment": "SMS ยาวเกิน 2 segment",
"rejected_by": "usr_manager_02"
}
}template.publishedเผยแพร่เวอร์ชันใหม่
ส่งเมื่อ: POST /publish
{
"id": "evt_01JB7Q03",
"type": "template.published",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "tpl_appointment_reminder",
"published_version": 4,
"previous_version": 3,
"published_at": "2026-10-12T13:06:00+07:00"
}
}template.archivedเก็บถาวร
ส่งเมื่อ: DELETE mode=archive
{
"id": "evt_01JB7Q04",
"type": "template.archived",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "tpl_promo_september",
"status": "archived",
"archived_at": "2026-10-12T11:40:00+07:00"
}
}ส่งซ้ำเมื่อปลายทางไม่ตอบ
- 1ทันที
- 21 นาที
- 35 นาที
- 430 นาที
- 52 ชั่วโมง
- 66 ชั่วโมง
- 724 ชั่วโมง (ครั้งสุดท้าย)
ครบทุกครั้งแล้วยังล้มเหลว → ปิด endpoint อัตโนมัติและส่งอีเมลแจ้งผู้ดูแล · ดูประวัติการส่งและกดส่งซ้ำได้ในแดชบอร์ด
ตรวจลายเซ็น
# ลายเซ็นอยู่ในหัว Siang-Signature: t=<unix>,v1=<hex>
# คำนวณ HMAC-SHA256(secret, "<t>.<raw body>") แล้วเทียบกับ v1
printf '%s' "$T.$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET"import crypto from 'node:crypto';
// ใช้ raw body (ยังไม่ parse JSON) เท่านั้น
export function verify(rawBody, sigHeader, secret) {
const parts = Object.fromEntries(sigHeader.split(',').map((p) => p.split('=')));
const age = Math.abs(Date.now() / 1000 - Number(parts.t));
if (age > 300) return false; // เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
const expected = crypto.createHmac('sha256', secret).update(parts.t + '.' + rawBody).digest('hex');
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}import hmac, hashlib, time
def verify(raw_body: bytes, sig_header: str, secret: str) -> bool:
parts = dict(p.split("=", 1) for p in sig_header.split(","))
if abs(time.time() - int(parts["t"])) > 300:
return False # เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
msg = parts["t"].encode() + b"." + raw_body
expected = hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])Errors — รหัสข้อผิดพลาด
ทุก error ตอบกลับเป็น JSON รูปแบบเดียวกัน พร้อม request_id สำหรับแจ้งทีมสนับสนุน · รหัส HTTP บอกกลุ่มของปัญหา ส่วน error.code บอกสาเหตุที่แน่นอน (ใช้เขียนเงื่อนไขในโค้ดได้ เพราะไม่เปลี่ยนตามภาษา)
- 4xx คำขอไม่ถูกต้อง — แก้ที่ฝั่งผู้เรียก ส่งซ้ำแบบเดิมจะได้ผลเดิม
- 5xx ปัญหาฝั่งระบบ — ลองใหม่แบบเว้นระยะ (exponential backoff) พร้อม Idempotency-Key
{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"param": "items[0].quantity",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.siang.example/errors#invalid_request"
}
}| HTTP | code | ความหมาย | วิธีแก้ |
|---|---|---|---|
| 400 | invalid_request | คำขอไม่ถูกต้อง ฟิลด์ขาด ชนิดผิด หรือค่าอยู่นอกช่วงที่รับ — ชื่อฟิลด์ที่ผิดอยู่ใน error.param | ตรวจ body/query ตาม schema ของ endpoint แล้วส่งใหม่ |
| 400 | invalid_json | JSON อ่านไม่ได้ body ไม่ใช่ JSON ที่ถูกต้อง หรือไม่ได้ส่งหัว Content-Type: application/json | ใช้ JSON.stringify / json= ของไลบรารี และตั้ง Content-Type ให้ถูก |
| 400 | unsupported_version | ไม่รู้จักเวอร์ชัน API ค่าในหัว Siang-Version ไม่ตรงกับเวอร์ชันที่มี หรือเวอร์ชันถูกปิดแล้ว | ใช้ 2026-08-01 (ล่าสุด) หรือ 2025-11-15 ที่ยังรองรับ |
| 401 | unauthenticated | ไม่ได้ยืนยันตัวตน ไม่มีหัว Authorization หรือรูปแบบไม่ใช่ Bearer <key> | ส่งหัว Authorization: Bearer sg_test_… (sandbox) หรือ sg_live_… (production) |
| 401 | invalid_api_key | API key ไม่ถูกต้อง key ถูกยกเลิก หมุนใหม่แล้ว หรือใช้ key ของ sandbox กับ production | สร้าง key ใหม่ในแดชบอร์ด และตรวจว่า base URL ตรงกับชนิดของ key |
| 403 | insufficient_scope | สิทธิ์ของ key ไม่พอ key นี้ไม่มี scope ที่ endpoint ต้องการ (เช่น ส่ง SMS ด้วย key ที่มีแค่ messages:read) | เพิ่ม scope ให้ key ในแดชบอร์ด หรือใช้ key ของระบบที่มีสิทธิ์ |
| 403 | account_suspended | บัญชีถูกระงับชั่วคราว บัญชีถูกระงับจากยอดค้างชำระหรือมีรายงานสแปมเกินเกณฑ์ (complaint > 0.3%) | ติดต่อทีมสนับสนุนพร้อม request_id · ตรวจรายชื่อผู้รับและความยินยอม |
| 404 | resource_not_found | ไม่พบรายการ รหัสที่ส่งมาไม่มีอยู่ หรือเป็นของบัญชีอื่น | ตรวจรหัสและ key ว่าเป็นของบัญชี/สภาพแวดล้อมเดียวกัน |
| 409 | idempotency_conflict | Idempotency-Key ซ้ำแต่เนื้อหาต่าง ใช้ Idempotency-Key เดิมกับ body ที่ไม่เหมือนเดิมภายใน 24 ชม. | สร้าง key ใหม่ทุกคำขอที่ต่างกัน (UUID v4) · ส่งซ้ำแบบเดิมได้ผลเดิม |
| 429 | rate_limited | เรียกเกินโควตา เกินจำนวนคำขอต่อวินาที/นาทีของ key หรือ endpoint | รอตามหัว Retry-After แล้วลองใหม่แบบเว้นระยะเพิ่มขึ้น (exponential backoff + jitter) |
| 500 | internal_error | ระบบขัดข้อง เกิดข้อผิดพลาดที่ฝั่ง SIANG — ข้อความยังไม่ถูกส่ง | ลองใหม่พร้อม Idempotency-Key เดิม · ถ้าเกิดซ้ำแจ้ง request_id |
| 404 | template_not_found | ไม่พบแม่แบบ template_id ไม่มี หรือถูกลบแล้ว | ดูรายการด้วย GET /v1/templates |
| 409 | template_not_published | แม่แบบยังไม่เผยแพร่ แม่แบบไม่มีเวอร์ชันที่อนุมัติและเผยแพร่ จึงยังใช้ส่งจริงไม่ได้ | ส่งเวอร์ชันให้อนุมัติแล้วเรียก /publish (sandbox ใช้ฉบับร่างได้) |
| 422 | variable_missing | ตัวแปรในแม่แบบขาด แม่แบบใช้ตัวแปรที่ไม่ได้ส่งมาใน variables และไม่มี default | ส่งตัวแปรให้ครบตาม variables[] ของแม่แบบ หรือใส่ |default:"…" |
| 422 | variable_type_mismatch | ชนิดตัวแปรไม่ตรง เช่น appointment_at ต้องเป็นเวลา ISO 8601 แต่ส่งข้อความธรรมดามา | ส่งค่าตามชนิดที่ประกาศใน variables[].type |
| 422 | template_syntax_error | รูปแบบแม่แบบผิด วงเล็บ {{ }} ไม่ครบคู่ หรือใช้ตัวกรองที่ไม่รู้จัก | ใช้ตัวกรองที่รองรับ: date time datetime upper baht default |
| 409 | version_conflict | เวอร์ชันชนกัน แก้แม่แบบจากเวอร์ชันเก่า (base_version ไม่ใช่ล่าสุด) | ดึงเวอร์ชันล่าสุดแล้วรวมการแก้ไขก่อนส่งใหม่ |
| 409 | template_in_use | แม่แบบถูกใช้งานอยู่ ลบไม่ได้เพราะมีกำหนดการส่งหรือแคมเปญที่ยังไม่จบอ้างถึง | ยกเลิกกำหนดการที่อ้างถึงก่อน หรือเก็บถาวร (archive) แทน |
ไม่พบรหัสที่ค้นหา
Rate limit — โควตาการเรียก
| ขอบเขต | โควตา | Burst | หมายเหตุ |
|---|---|---|---|
| POST /v1/templates/{id}/render | 60 ครั้ง/นาที/บัญชี | 20 | ไม่คิดเงิน |
| สร้าง/แก้แม่แบบและเวอร์ชัน | 30 ครั้ง/นาที | — | |
| จำนวนแม่แบบต่อบัญชี | 500 แม่แบบ | — | archive ไม่นับ |
| ขนาดเนื้อหาต่อช่อง | 64 KB | — | อีเมล HTML · ช่องอื่นตามข้อจำกัดช่องทาง |
Siang-RateLimit-Limitโควตาของช่วงเวลาSiang-RateLimit-Remainingครั้งที่เหลือSiang-RateLimit-Resetวินาทีจนโควตาเริ่มใหม่- เกินโควตา → 429 พร้อม
Retry-After· แนะนำลองใหม่แบบเว้นระยะเพิ่มขึ้น + สุ่มเล็กน้อย (jitter)
HTTP/1.1 429 Too Many Requests
Siang-RateLimit-Limit: 100
Siang-RateLimit-Remaining: 0
Siang-RateLimit-Reset: 23
Retry-After: 23
{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา ลองใหม่ใน 23 วินาที",
"request_id": "req_2Kd9QwZ1"
}
}เวอร์ชันและ Changelog
เลือกเวอร์ชันด้วยหัว Siang-Version (ไม่ส่ง = เวอร์ชันที่ผูกกับ API key) · การเปลี่ยนที่ไม่ทำให้โค้ดเดิมพัง (เพิ่มฟิลด์/endpoint) ออกในเวอร์ชันเดิมได้ · การเปลี่ยนที่ทำให้พังออกเป็นเวอร์ชันใหม่เสมอ และแจ้งล่วงหน้าอย่างน้อย 6 เดือนก่อนปิดเวอร์ชันเก่า
| เวอร์ชัน | สถานะ | รองรับถึง |
|---|---|---|
2026-08-01 | ปัจจุบัน | — |
2025-11-15 | ยังรองรับ | 30 ก.ย. 2570 |
2024-06-01 | เลิกใช้แล้ว | 31 ธ.ค. 2569 |
- เพิ่ม
2026-08-01ตัวกรอง baht และ default:"…"
- เปลี่ยน
2026-08-01render คืน error ทุกจุดใน details[] แทนที่จะหยุดที่จุดแรก
- เพิ่ม
2025-11-15ขั้นอนุมัติ 2 คน (POST …/versions/{v}/review) และ scope templates:approve
- แก้ไข
2025-11-15date ในภาษาไทยแสดงปี ค.ศ. — ตอนนี้แสดง พ.ศ.
- ความปลอดภัย
2025-11-15escape HTML ของค่าตัวแปรในอีเมลอัตโนมัติ (กันการฝังสคริปต์)
- เปลี่ยน
2025-11-15แก้เนื้อหาผ่านเวอร์ชันเท่านั้น (PATCH แก้ได้แค่ข้อมูลประกอบ)
- เลิกใช้
2025-11-15เลิกใช้ไวยากรณ์ ${var} — ใช้ {{var}} (2024-06-01 ยังรับถึง 31 ธ.ค. 2569)
- เพิ่ม
2024-06-01ประกาศชนิดตัวแปร (variables[].type)
- เพิ่ม
2024-06-01แม่แบบหลายภาษา (content.th / content.en)
เครื่องมือ: ตัวแสดงผลแม่แบบ
แก้แม่แบบและค่าตัวแปร JSON → ผลลัพธ์ทุกช่องทางทันที + error เมื่อตัวแปรขาด/ผิดชนิด/ไวยากรณ์ผิด (กฎเดียวกับ POST /render) — ทำงานในเบราว์เซอร์ทั้งหมด ไม่ได้เรียก API จริง (กฎเดียวกับฝั่งเซิร์ฟเวอร์ในเอกสารนี้)
แม่แบบ tpl_appointment_reminder (แก้ได้)
ค่าตัวแปร (JSON)
| ตัวแปร | ชนิด | บังคับ | ใช้ในช่อง | สถานะ |
|---|