Verify phone numbers
Send one-time codes and check them.
The OTP endpoints generate a code, send it by SMS and check what the user enters. You never have to store codes yourself.
1. Send a code
curl https://api.appstractone.com/v1/otp/send \
-H "Authorization: Bearer $APPSTRACT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "0241234567",
"from": "MYSHOP",
"length": 6,
"expiresInMinutes": 5,
"message": "Your MyShop code is {{code}}. It expires in {{minutes}} minutes."
}'| Field | Default | Description |
|---|---|---|
length | 6 | Digits in the code, 4 to 8. |
expiresInMinutes | 5 | Minutes until the code expires, 1 to 30. |
message | Your verification code is {{code}}. It expires in {{minutes}} minutes. | Must contain {{code}}. |
Sending a new code to a number replaces any code still pending for it. The response includes an id; keep it to verify the code.
2. Verify the code
curl https://api.appstractone.com/v1/otp/verify \
-H "Authorization: Bearer $APPSTRACT_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "id": "otp_01M6MJSBXRZS9JGB57380Y48E5", "code": "102028" }'You can send to instead of id to check the latest code sent to that number.
status | Meaning |
|---|---|
valid | The code is correct. It cannot be used again. |
invalid | The code is wrong. The user can try again. |
expired | The code has expired. Send a new one. |
Limits
- After 5 wrong attempts, the code is locked and verify returns
429withotp_locked. Send a new code. - Each number can receive a limited number of codes per hour. Beyond it, send returns
429withotp_rate_limited.
Privacy
Codes are stored as one-way hashes, and the code is removed from the stored message text once it has been sent.