POST
Send a one-time passcode over SMS, WhatsApp, voice, or email. The response returns a reference_id you’ll pass to Validate OTP to confirm the code the user enters.
/api/v1/messaging/otpHeaders
| Header | Required | Description |
|---|---|---|
Authorization | Yes | Your app’s secret key, sent as-is. |
AppId | Yes | The App ID from your dashboard. |
Content-Type | Yes | application/json |
Body parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
sender_id | string | Yes | A registered Sender ID to send from. |
destination | string | Yes | Recipient phone number (for SMS, WhatsApp, voice). |
channel | string | Yes | Delivery channel: sms, whatsapp, voice, or email. |
email | string | No | Recipient email address — required when channel is email. |
length | integer | No | Number of digits in the code, 4–10. Default 6. |
expiry | integer | No | Minutes before the code expires. Default 10. |
priority | boolean | No | Send in priority mode. Default false. |
otp | integer | No | Supply your own code (4–10 digits) instead of having Dojah generate one. |
Response
Returns200 OK with an entity object. Store the reference_id — it’s the only way to validate the code later.
| Field | Type | Description |
|---|---|---|
reference_id | string | Unique ID for this OTP. Pass it to Validate OTP. |
destination | string | The phone number or email the code was sent to. |
status | string | Human-readable delivery status, e.g. SMS sent successfully. |
Errors
| Code | Meaning |
|---|---|
400 | Bad request — a required field is missing or malformed. |
401 | Unauthorized — check your Authorization key and AppId. |
402 | Payment required — your wallet balance is too low. Fund your wallet. |
422 | Unprocessable — e.g. an unregistered sender_id or invalid channel. |
429 | Too many requests — slow your request rate and retry. |
curl -X POST "https://api.dojah.io/api/v1/messaging/otp" \
-H "Authorization: {{secret_key}}" \
-H "AppId: {{app_id}}" \
-H "Content-Type: application/json" \
-d '{
"sender_id": "Dojah",
"destination": "2348012345678",
"channel": "sms",
"length": 6,
"expiry": 10
}'
const res = await fetch("https://api.dojah.io/api/v1/messaging/otp", {
method: "POST",
headers: {
Authorization: process.env.DOJAH_SECRET_KEY,
AppId: process.env.DOJAH_APP_ID,
"Content-Type": "application/json",
},
body: JSON.stringify({
sender_id: "Dojah",
destination: "2348012345678",
channel: "sms",
length: 6,
expiry: 10,
}),
});
const data = await res.json();
import os, requests
res = requests.post(
"https://api.dojah.io/api/v1/messaging/otp",
headers={
"Authorization": os.environ["DOJAH_SECRET_KEY"],
"AppId": os.environ["DOJAH_APP_ID"],
},
json={
"sender_id": "Dojah",
"destination": "2348012345678",
"channel": "sms",
"length": 6,
"expiry": 10,
},
)
data = res.json()
<?php
$ch = curl_init("https://api.dojah.io/api/v1/messaging/otp");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
"Authorization: " . getenv("DOJAH_SECRET_KEY"),
"AppId: " . getenv("DOJAH_APP_ID"),
"Content-Type: application/json",
],
CURLOPT_POSTFIELDS => json_encode([
"sender_id" => "Dojah",
"destination" => "2348012345678",
"channel" => "sms",
"length" => 6,
"expiry" => 10,
]),
]);
$data = json_decode(curl_exec($ch), true);
{
"entity": {
"reference_id": "edd37ab5-48ec-4481-8cf9-ba5chu7c41f7",
"destination": "2348012345678",
"status": "SMS sent successfully"
}
}