บันทึก Consent POST
บันทึกความยินยอม (PDPA consent) ของเบอร์มือถือหนึ่งเบอร์ ทุกครั้งที่เรียกจะเพิ่มรายการใหม่ (ไม่แก้ไขรายการเดิม) — หากผู้รับถอนความยินยอม ให้บันทึกใหม่ด้วย granted: false
Authorization
ใช้ API Key (การยืนยันตัวตน) — ส่ง header Authorization: Bearer <API_KEY> (API Key ขึ้นต้นด้วย smsk_)
HTTP Request
http
POST https://public-api.smsup-plus.com/Consent/saveconsentContent Type
application/json
Parameter Description
| Property | Type | Required | Description |
|---|---|---|---|
mobile | string | Required | เบอร์มือถือ ระบบตัดอักขระที่ไม่ใช่ตัวเลขและ + ออก แล้วต้องเหลือตัวเลข 10–15 หลัก |
consentType | string | Required | ประเภทความยินยอม (เช่น marketing, transactional) |
granted | boolean | Required | true = ยินยอม, false = ไม่ยินยอม / ถอนความยินยอม |
source | string | Optional | ช่องทางที่ได้รับความยินยอม (เช่น web, sms-reply) |
note | string | Optional | หมายเหตุเพิ่มเติม |
Response Description
| Property | Type | Description |
|---|---|---|
status | number | 200 เมื่อบันทึกสำเร็จ |
description | string | Consent recorded. |
data.consentId | string | รหัสรายการ consent (UUID) |
data.createdAt | string | เวลาที่บันทึก (ISO 8601, UTC) |
ตัวอย่าง Request
bash
curl -X POST 'https://public-api.smsup-plus.com/Consent/saveconsent' \
-H 'Authorization: Bearer <API_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"mobile": "0812345678",
"consentType": "marketing",
"granted": true,
"source": "web",
"note": "สมัครรับข่าวสารผ่านหน้าเว็บ"
}'js
const res = await fetch('https://public-api.smsup-plus.com/Consent/saveconsent', {
method: 'POST',
headers: { Authorization: 'Bearer <API_KEY>', 'Content-Type': 'application/json' },
body: JSON.stringify({
mobile: '0812345678',
consentType: 'marketing',
granted: true,
source: 'web',
note: 'สมัครรับข่าวสารผ่านหน้าเว็บ',
}),
})
console.log(await res.json())ตัวอย่าง Response
json
{
"status": 200,
"description": "Consent recorded.",
"data": {
"consentId": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"createdAt": "2026-11-16T03:15:42.512345678Z"
}
}Error ที่อาจเจอ
endpoint นี้ตอบ HTTP 200 เสมอ (ยกเว้น error การยืนยันตัวตน) — ให้ตรวจผลลัพธ์จากฟิลด์ status ใน body
| HTTP | Response | สาเหตุ |
|---|---|---|
| 200 | {"status":400,"description":"mobile, consentType, and granted are required."} | body ไม่ใช่ JSON หรือขาด mobile / consentType / granted |
| 200 | {"status":400,"description":"Invalid mobile number."} | เบอร์มีตัวเลขน้อยกว่า 10 หรือมากกว่า 15 หลัก |
| 200 | {"status":500,"description":"Failed to save consent."} | ระบบบันทึกไม่สำเร็จ ลองใหม่อีกครั้ง |
| 200 | {"status":401,"description":"Unauthorized."} | ไม่สามารถระบุบัญชีจากข้อมูลยืนยันตัวตนได้ |
| 401 | {"error":"invalid api key"} | API Key ไม่ถูกต้อง — ดู Error |
WARNING
การบันทึก granted: false (ถอนความยินยอม) อาจทำให้ข้อความ SMS ที่ส่งถึงเบอร์นี้ภายหลังถูกปฏิเสธ ตามการตั้งค่า consent ของบัญชีคุณ — มีผลกับการส่งครั้งถัดไปทันที
TIP
- ใช้รูปแบบเบอร์เดียวกันทุกครั้ง เพราะ ตรวจสอบ Consent ค้นหาเบอร์แบบตรงตัว
- ระบบเก็บ IP และ User-Agent ของผู้เรียกไว้กับรายการเป็นหลักฐานการให้ความยินยอม
