Verify Code
Verify a one-time password submitted by the user.
Verify a Code
verify.ts
import { YourSend } from 'yoursend';
const ys = new YourSend({ apiKey: 'ys_live_...' });
const result = await ys.check({
message_id: '8f14e45f-ceea-467a-9b3a-1d2c3e4f5a6b', // from the send response
code: '123456', // user-provided code
});
if (result.verified) {
// Code is correct — grant access
} else {
// Wrong code — result.remaining_attempts shows tries left
}Response
Success response
{
"message_id": "8f14e45f-ceea-467a-9b3a-1d2c3e4f5a6b",
"status": "verified",
"verified": true
}Wrong code (HTTP 200)
{
"message_id": "8f14e45f-ceea-467a-9b3a-1d2c3e4f5a6b",
"status": "pending",
"verified": false,
"remaining_attempts": 4
}Error Handling
| Outcome | HTTP | Meaning |
|---|---|---|
| verified: false | 200 | Code doesn't match. remaining_attempts shows tries left. |
| expired | 400 | The code has expired (default: 10 min) |
| already_verified | 400 | The code has already been used |
| max_attempts | 400 | Too many wrong attempts (5 max) |
| not_found | 404 | No OTP found for this message_id |