Send Token
The Send Token API allows businesses to trigger one-time passwords (OTPs) across any supported messaging channel on Termii. The OTPs are randomly generated and can be customized with an optional expiry time to enhance security. OTPs are generated and sent to the phone number and can only be verified using our Verify Token API .
Endpoint :
https://BASE_URL/api/sms/otp/send
Request Type : POST
| Options | Required | Description |
|---|---|---|
| api_key | yes | string Your API key (It can be found on your Termii dashboard). |
| pin_type | yes | Specifies the format of the OTP to be generated and sent. Use NUMERIC to generate an OTP containing only numbers (e.g., 457891). Use ALPHANUMERIC to generate an OTP containing both letters and numbers (e.g., AD4891F) |
| to | yes | string Represents the recipient's phone number. The phone number must be provided in international format (e.g., 2347065250817), without spaces or special characters. |
| from | yes | string Represents the approved Sender ID which can be alphanumeric or numeric. |
| channel | yes | string This is the route through which the message is sent. It is either dnd, or generic |
| pin_attempts | yes | integer Example: 3Represents the number of times the PIN can be attempted before expiration. It has a minimum of one attempt |
| pin_time_to_live | yes | integer Example: 1Represents how long the PIN is valid before expiration. The time is in minutes. The minimum time value is 0 and the maximum time value is 60 |
| pin_length | yes | integer Example: 4 The length of the PIN code.It has a minimum of 4 and maximum of 8. |
| pin_placeholder | yes | string Example: "< 1234 >" PIN placeholder. Right before sending the message, PIN code placeholder will be replaced with generate PIN code. |
| message_text | yes | string The content of the message to be delivered to the recipient's phone number. |
{
"api_key" : "Your API Key",
"message_type" : "NUMERIC",
"to" : "2347065250817",
"from" : "Tommy",
"channel" : "generic",
"pin_attempts" : 10,
"pin_time_to_live" : 5,
"pin_length" : 8,
"pin_placeholder" : "< 12345678 >",
"message_text" : "Your pin is to authenticate your transaction is < 12345678 >",
"pin_type" : "NUMERIC"
}
var data = {
"api_key" : "Your API Key",
"message_type" : "NUMERIC",
"to" : "2347065250817",
"from" : "Tommy",
"channel" : "generic",
"pin_attempts" : 10,
"pin_time_to_live" : 5,
"pin_length" : 8,
"pin_placeholder" : "< 12345678 >",
"message_text" : "Your pin is to authenticate your transaction is < 12345678 >",
"pin_type" : "NUMERIC",
};
var data = JSON.stringify(data);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", "https://BASE_URL/api/sms/otp/send");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
var request = require('request');
var data = {
"api_key" : "Your API Key",
"message_type" : "NUMERIC",
"to" : "2347065250817",
"from" : "Tommy",
"channel" : "generic",
"pin_attempts" : 10,
"pin_time_to_live" : 5,
"pin_length" : 8,
"pin_placeholder" : "< 12345678 >",
"message_text" : "Your pin is to authenticate your transaction is < 12345678 >",
"pin_type" : "NUMERIC"
};
var options = {
'method': 'POST',
'url': 'https://BASE_URL/api/sms/otp/send',
'headers': {
'Content-Type': ['application/json', 'application/json']
},
body: JSON.stringify(data)
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
url = "https://BASE_URL/api/sms/otp/send"
payload = {
"api_key" : "Your API Key",
"message_type" : "NUMERIC",
"to" : "2347065250817",
"from" : "Tommy",
"channel" : "generic",
"pin_attempts" : 10,
"pin_time_to_live" : 5,
"pin_length" : 8,
"pin_placeholder" : "< 12345678 >",
"message_text" : "Your pin is to authenticate your transaction is < 12345678 >",
"pin_type" : "NUMERIC"
}
headers = {
'Content-Type': 'application/json',
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)
RestClient restClient = new RestClient("https://BASE_URL/api/sms/otp/send");
RestClient restClient = new RestClient("https://BASE_URL/api/sms/otp/send");
// Create the JSON payload
JObject objectBody = new JObject();
objectBody.Add("api_key", "Your API Key");
objectBody.Add("message_type", "NUMERIC");
objectBody.Add("to", "2347065250817");
objectBody.Add("from", "Tommy");
objectBody.Add("channel", "generic");
objectBody.Add("pin_attempts", 10);
objectBody.Add("pin_time_to_live", 5);
objectBody.Add("pin_length", 8);
objectBody.Add("pin_placeholder", "< 12345678 >");
objectBody.Add("message_text", "Your pin to authenticate your transaction is < 12345678 >");
objectBody.Add("pin_type", "NUMERIC");
// Create the request
RestRequest restRequest = new RestRequest(Method.POST);
restRequest.AddHeader("Content-Type", "application/json");
restRequest.AddParameter("application/json", objectBody, ParameterType.RequestBody);
// Execute the request
IRestResponse restResponse = restClient.Execute(restRequest);
// Print response content
Console.WriteLine(restResponse.Content);
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://BASE_URL/api/sms/otp/send")
.header("Content-Type", "application/json")
.body("{\n" +
" \"api_key\": \"Your API Key\",\n" +
" \"message_type\": \"NUMERIC\",\n" +
" \"to\": \"2347065250817\",\n" +
" \"from\": \"Tommy\",\n" +
" \"channel\": \"generic\",\n" +
" \"pin_attempts\": 10,\n" +
" \"pin_time_to_live\": 5,\n" +
" \"pin_length\": 8,\n" +
" \"pin_placeholder\": \"< 12345678 >\",\n" +
" \"message_text\": \"Your pin to authenticate your transaction is < 12345678 >\",\n" +
" \"pin_type\": \"NUMERIC\"\n" +
"}")
.asString();
System.out.println(response.getBody());
<?php
$curl = curl_init();
$data = array(
"api_key" => "Your API Key",
"message_type" => "NUMERIC",
"to" => "2347065250817",
"from" => "Tommy",
"channel" => "generic",
"pin_attempts" => 10,
"pin_time_to_live" => 5,
"pin_length" => 8,
"pin_placeholder" => "< 12345678 >",
"message_text" => "Your pin to authenticate your transaction is < 12345678 >",
"pin_type" => "NUMERIC"
);
$post_data = json_encode($data);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://BASE_URL/api/sms/otp/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Sample Response - 200 OK
{
"smsStatus": "Message Sent",
"phone_number": "2347065250817",
"to": "2347065250817",
"pinId": "b1f2242a-44c5-4eed-94bc-8d37b67ef219",
"pin_id": "b1f2242a-44c5-4eed-94bc-8d37b67ef219",
"message_id_str": "3017600245086449408013699",
"status": "200"
}