ยืนยัน OTP POST
ใช้ตรวจรหัส OTP ที่ผู้ใช้กรอก กับ otpId ที่ได้จาก ขอ OTP ผลการตรวจทุกกรณีตอบกลับเป็น HTTP 200 — ให้ดูที่ valid และ status.code
Authorization
ใช้ API Key (การยืนยันตัวตน) ส่งใน header Authorization: Bearer <API_KEY>
HTTP Request
http
POST https://public-api.smsup-plus.com/OTP/verifyotpContent Type
application/json (รับเฉพาะ JSON)
Parameter Description
| Property | Type | Required | Description |
|---|---|---|---|
otpid | string | Required | otpId จาก ขอ OTP |
otpcode | string | Required | รหัส OTP ที่ผู้ใช้กรอก (รวม prefix ถ้า OTP config กำหนดไว้) |
Response Description
| Property | Type | Description |
|---|---|---|
valid | boolean | true = รหัสถูกต้อง |
otpId | string | otpid ที่ส่งมา |
expired | boolean | true เมื่อ OTP หมดอายุหรือไม่พบ (ไม่มีฟิลด์นี้ถ้าเป็น false) |
maxAttemptsReached | boolean | true เมื่อกรอกผิดครบจำนวนครั้งแล้ว (ไม่มีฟิลด์นี้ถ้าเป็น false) |
remainingAttempts | number | จำนวนครั้งที่ยังกรอกได้ |
status.code | string | ดูตารางด้านล่าง |
status.message | string | ดูตารางด้านล่าง |
status.description | string | ดูตารางด้านล่าง |
ผลการตรวจ
status.code | status.message | status.description | ความหมาย |
|---|---|---|---|
200 | VERIFIED | OTP verified successfully | รหัสถูกต้อง (valid: true) — OTP นี้ใช้ยืนยันซ้ำไม่ได้อีก |
401 | INVALID_CODE | Invalid OTP code. 2 attempts remaining | รหัสผิด ตัวเลขคือจำนวนครั้งที่เหลือ — หรือ OTP นี้ถูกยืนยันสำเร็จไปแล้ว (เหลือ 0) |
410 | EXPIRED | OTP has expired | OTP หมดอายุ หรือ otpid ไม่ถูกต้อง (expired: true) |
429 | MAX_ATTEMPTS | Maximum verification attempts reached | กรอกผิดครบจำนวนครั้งที่ OTP config กำหนด (ค่าเริ่มต้น 3) OTP นี้ใช้ไม่ได้อีก (maxAttemptsReached: true) |
TIP
- ทุกครั้งที่ตรวจ (ถูกหรือผิด) นับเป็น 1 ครั้ง
- หลัง
MAX_ATTEMPTSหรือEXPIREDให้ผู้ใช้ ขอ OTP ใหม่ — ส่ง OTP ซ้ำ ไม่คืนจำนวนครั้งที่กรอกผิด และไม่ต่ออายุ OTP
ตัวอย่าง Request
bash
curl -X POST 'https://public-api.smsup-plus.com/OTP/verifyotp' \
-H 'Authorization: Bearer <API_KEY>' \
-H 'Content-Type: application/json' \
-d '{
"otpid": "7f3c9a1e-2b4d-4c6e-8a0f-1e3d5b7c9a2f",
"otpcode": "482913"
}'js
const res = await fetch('https://public-api.smsup-plus.com/OTP/verifyotp', {
method: 'POST',
headers: { Authorization: 'Bearer <API_KEY>', 'Content-Type': 'application/json' },
body: JSON.stringify({
otpid: '7f3c9a1e-2b4d-4c6e-8a0f-1e3d5b7c9a2f',
otpcode: '482913',
}),
})
console.log(await res.json())ตัวอย่าง Response
รหัสถูกต้อง:
json
{
"valid": true,
"otpId": "7f3c9a1e-2b4d-4c6e-8a0f-1e3d5b7c9a2f",
"remainingAttempts": 2,
"status": {
"code": "200",
"message": "VERIFIED",
"description": "OTP verified successfully"
}
}รหัสผิด:
json
{
"valid": false,
"otpId": "7f3c9a1e-2b4d-4c6e-8a0f-1e3d5b7c9a2f",
"remainingAttempts": 2,
"status": {
"code": "401",
"message": "INVALID_CODE",
"description": "Invalid OTP code. 2 attempts remaining"
}
}หมดอายุ:
json
{
"valid": false,
"otpId": "7f3c9a1e-2b4d-4c6e-8a0f-1e3d5b7c9a2f",
"expired": true,
"remainingAttempts": 0,
"status": {
"code": "410",
"message": "EXPIRED",
"description": "OTP has expired"
}
}Error ที่อาจเจอ
ดูภาพรวมที่ รหัสข้อผิดพลาด
| HTTP | Response | สาเหตุ |
|---|---|---|
| 400 | {"error":{"code":"400","message":"BAD_REQUEST","description":"Invalid request body"}} | body ไม่ใช่ JSON ที่ถูกต้อง หรือไม่มี otpid / otpcode |
| 404 | {"error":{"code":"404","message":"OTP_NOT_FOUND","description":"OTP not found for this account"}} | otpid เป็นของบัญชีอื่น (ไม่นับเป็นการกรอก 1 ครั้ง) |
| 429 | {"error":{"statusCode":"429","description":"rate limit exceeded: max 50 requests per second per account","message":"TOO_MANY_REQUESTS"}} | เรียกถี่เกินกำหนด — รอตาม header Retry-After |
| 500 | {"error":{"code":"500","message":"INTERNAL_SERVER_ERROR","description":"Failed to verify OTP"}} | ระบบตรวจ OTP ไม่สำเร็จชั่วคราว |
