OTP API
Send and verify one-time passcodes by SMS, email or WhatsApp.
NBM SMS generates, delivers and checks one-time passcodes for you, so your system never stores a code. Codes are 6 digits, single use, and expire after 30 minutes.
Send an OTP
Generates a new code and sends it by SMS — and by email too if you give an address. The code is never returned in the response.
Body
phone_numberstringrequiredWhere to send the code. See phone number format.
email_addressstringoptionalAlso email the same code to this address.
sender_namestringoptionalSend from one of your approved sender names, billed like a normal SMS. Leave it out to send free from the system sender
NBM.brand_namestringoptionaldefault: NBMThe name shown in the text, e.g. "Your NBM Shop code is 482913".
channelstringoptionaldefault: smssms or whatsapp.whatsapp_sourcestringoptionaldefault: defaultFor WhatsApp:
default (shared NBM number) or own (your connected number).| Status | error | When it happens |
|---|---|---|
| 400 | validation_error | phone_number is missing or empty. |
| 400 | creation_error | Sender name not approved or not yours, WhatsApp not available on your account, or not enough balance. |
| 401 | invalid_token | Missing or invalid API key. |
Free, from the system sender
curl -X POST https://sms.nbmbrand.com/api/v1/otps \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"phone_number": "0712345678",
"brand_name": "NBM Shop"
}'Your own sender name + email
curl -X POST https://sms.nbmbrand.com/api/v1/otps \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"phone_number": "0712345678",
"email_address": "asha@example.com",
"sender_name": "NBM",
"brand_name": "NBM Shop"
}'Response
200 OK
{
"success": true,
"status_code": 200,
"status_text": "OK",
"message": "otp has been sent",
"data": null
}Verify an OTP
Checks a code the user typed. This endpoint is public — it needs no API key — but call it from your server anyway, so that only a successful check on your side unlocks the action.
Body
codeintegerrequiredThe 6-digit code, as a JSON number (
482913, not "482913").phone_numberstringoptionalThe number the code was sent to.
email_addressstringoptionalThe email the code was sent to. Give the phone number, the email, or both.
A code can be verified once. A second check with the same code fails.
| Status | error | When it happens |
|---|---|---|
| 400 | validation_error | code is missing or 0, or neither phone nor email was given. |
| 400 | verification_error | No unused, unexpired code matches. |
curl -X POST https://sms.nbmbrand.com/api/v1/otps/verify \
-H "Content-Type: application/json" \
-d '{
"code": 482913,
"phone_number": "0712345678"
}'Response
200 OK
{
"success": true,
"status_code": 200,
"status_text": "OK",
"message": "otp has been verified",
"data": null
}Response
400 Bad Request
{
"success": false,
"status_code": 400,
"status_text": "Bad Request",
"message": "otp is invalid or has expired",
"error": "verification_error"
}Best practice
- Decide on your server. Your app sends the typed code to your backend; your backend calls Verify and only then signs the user in or resets the password. Never trust an "OTP OK" flag sent by the app or browser — it can be edited.
- Tie the result to the action. After a successful check, store "phone verified for this session / this account" on your server for a few minutes, and use it once.
- Limit requests. Allow a resend every 60 seconds and a handful per number per hour, to protect your balance and your users.
- Don't reveal accounts. Show the same "If this number is registered, we sent a code" message whether or not the number exists.
- Use the account's saved number. For password resets, send the code to the number on the account — not to a number typed into the form.