How OTP works
Send the code
Call send with
type: otp. Write%otp_code%in your message where the code should appear.Your user types it in
They receive a 6-digit code by SMS and enter it on your website or app.
Verify it
Call verify with the number and the code. Only let the user continue when
statusissuccess.
Codes are 6 digits and expire after 5 minutes. You never generate, store or compare codes yourself.
Send an OTP
/api/v3/sms/sendGenerates a code and sends it by SMS. The code is never included in the response.
Body parameters
| Parameter | Required | Description |
|---|---|---|
recipientstring | Required | One phone number per request, for example 233552690110. |
sender_idstring | Required | Your approved Sender ID, up to 11 characters. This is the name people see. How to get a Sender ID. |
typestring | Required | Must be otp. |
messagestring | Required | Your message with %otp_code% where the code goes, for example Your login code is %otp_code%. If you leave it out, the code is added to the end. |
curl -X POST "https://app.nkomosms.com/api/v3/sms/send" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"recipient": "233552690110",
"sender_id": "YourBrand",
"type": "otp",
"message": "Your login code is %otp_code%"
}'<?php
$ch = curl_init('https://app.nkomosms.com/api/v3/sms/send');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN',
'Content-Type: application/json',
'Accept: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'recipient' => '233552690110',
'sender_id' => 'YourBrand',
'type' => 'otp',
'message' => 'Your login code is %otp_code%',
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
if (($response['status'] ?? '') === 'success') {
print_r($response['data']);
} else {
echo $response['message'] ?? 'Request failed';
}// Node.js 18 or newer (fetch is built in)
const res = await fetch('https://app.nkomosms.com/api/v3/sms/send', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
"recipient": "233552690110",
"sender_id": "YourBrand",
"type": "otp",
"message": "Your login code is %otp_code%"
}),
});
const result = await res.json();
if (result.status === 'success') {
console.log(result.data);
} else {
console.error(result.message);
}import requests
response = requests.post(
"https://app.nkomosms.com/api/v3/sms/send",
headers={"Authorization": "Bearer YOUR_API_TOKEN", "Accept": "application/json"},
json={
"recipient": "233552690110",
"sender_id": "YourBrand",
"type": "otp",
"message": "Your login code is %otp_code%"
},
timeout=30,
)
result = response.json()
if result["status"] == "success":
print(result["data"])
else:
print(result["message"]){
"status": "success",
"message": "Your message was successfully delivered",
"data": "…"
}{
"status": "error",
"message": "A human-readable description of the error."
}Verify an OTP
/api/v3/otp/verifyChecks the code your user typed. Verifying is free.
Body parameters
| Parameter | Required | Description |
|---|---|---|
recipientstring | Required | The number the OTP was sent to, for example 233552690110. |
codestring | Required | The code your user entered, for example 482910. |
curl -X POST "https://app.nkomosms.com/api/v3/otp/verify" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"recipient": "233552690110",
"code": "482910"
}'<?php
$ch = curl_init('https://app.nkomosms.com/api/v3/otp/verify');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN',
'Content-Type: application/json',
'Accept: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'recipient' => '233552690110',
'code' => '482910',
]),
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
if (($response['status'] ?? '') === 'success') {
print_r($response['data']);
} else {
echo $response['message'] ?? 'Request failed';
}// Node.js 18 or newer (fetch is built in)
const res = await fetch('https://app.nkomosms.com/api/v3/otp/verify', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
"recipient": "233552690110",
"code": "482910"
}),
});
const result = await res.json();
if (result.status === 'success') {
console.log(result.data);
} else {
console.error(result.message);
}import requests
response = requests.post(
"https://app.nkomosms.com/api/v3/otp/verify",
headers={"Authorization": "Bearer YOUR_API_TOKEN", "Accept": "application/json"},
json={
"recipient": "233552690110",
"code": "482910"
},
timeout=30,
)
result = response.json()
if result["status"] == "success":
print(result["data"])
else:
print(result["message"]){
"status": "success",
"data": {
"recipient": "233552690110",
"verified": true
},
"message": "Code verified."
}{
"status": "error",
"message": "A human-readable description of the error."
}Verify errors
| HTTP | Meaning |
|---|---|
422 | The code is wrong or has expired, or a field is missing. Ask the user to try again or send a new code. |
404 | No OTP was sent to this number from your account in the last 15 minutes. Send a new OTP first. |
429 | Too many attempts. After 5 wrong codes the number is locked for 10 minutes. |
403 | Your account does not have API access. Contact support. |
Need help with your integration?
Message us on WhatsApp, call +233 55 269 0110 or email support@nkomosms.com. Send us the request you made and the response you got, but never your API token.