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: 3 Represents 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: 1 Represents 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",
"pin_type" : "NUMERIC",
"to" : "eg. 2348109077743",
"from" : "Approved Sender ID or Configuration ID",
"channel" : "dnd",
"pin_attempts" : 10,
"pin_time_to_live" : 5,
"pin_length" : 6,
"pin_placeholder" : "< 123456 >",
"message_text" : "Your pin is < 123456>",
}
var data = {
"api_key" : "Your API key",
"pin_type" : "NUMERIC",
"to" : "eg. 2348109077743",
"from" : "Approved Sender ID or Configuration ID",
"channel" : "dnd",
"pin_attempts" : 10,
"pin_time_to_live" : 5,
"pin_length" : 6,
"pin_placeholder" : "< 123456 >",
"message_text" : "Your pin is < 123456 >",
};
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",
"pin_type" : "NUMERIC",
"to" : "eg. 2348109077743",
"from" : "Approved Sender ID or Configuration ID",
"channel" : "dnd",
"pin_attempts" : 10,
"pin_time_to_live" : 5,
"pin_length" : 6,
"pin_placeholder" : "< 123456 >",
"message_text" : "Your pin is < 123456 >",
};
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",
"pin_type" : "NUMERIC",
"to" : "eg. 2348109077743",
"from" : "Approved Sender ID or Configuration ID",
"channel" : "dnd",
"pin_attempts" : 10,
"pin_time_to_live" : 5,
"pin_length" : 6,
"pin_placeholder" : "< 123456 >",
"message_text" : "Your pin is < 123456 >",
}
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");
//Creating Json object
JObject objectBody = new JObject();
objectBody.Add("api_key","Your API Key");
objectBody.Add("pin_type","NUMERIC");
objectBody.Add("to","+2348109077743");
objectBody.Add("from","Approved Sender ID or Configuration ID");
objectBody.Add("channel","dnd");
objectBody.Add("pin_attempts", 3);
objectBody.Add("pin_time_to_live", 0);
objectBody.Add("pin_length", 6);
objectBody.Add("pin_placeholder", "< 123456 >");
objectBody.Add("message_text", "Your pin is < 123456 >");
RestRequest restRequest = new RestRequest(Method.POST);
restRequest.AddHeader("Content-Type", "application/json");
restRequest.AddParameter("application/json", objectBody, ParameterType.RequestBody);
IRestResponse restResponse = restClient.Execute(restRequest);
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("{\r\n \"api_key\" : \"Your API key\",\r\n \"pin_type\" : \"NUMERIC\",\r\n \"to\" : \"eg. 2348109077743\",\r\n \"from\" : \"Approved Sender ID or Configuration ID\",\r\n \"channel\" : \"dnd\",\r\n \"pin_attempts\" : 10,\r\n \"pin_time_to_live\" : 5,\r\n \"pin_length\" : 6,\r\n \"pin_placeholder\" : \"< 123456 >\",\r\n \"message_text\" : \"Your pin is < 123456 >\",\r\n ")
.asString();
$curl = curl_init();
$data = array( "api_key" => "Your API key",
"pin_type" => "NUMERIC",
"to" => "eg. 2348109077743",
"from" => "Approved Sender ID or Configuration ID",
"channel" => "dnd",
"pin_attempts" => 10,
"pin_time_to_live" => 5,
"pin_length" => 6,
"pin_placeholder" => "< 123456 >",
"message_text" => "Your pin is < 123456 >",
);
$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": "a70b9b66-54dc-46ec-b81f-12531573fa38",
"pin_id": "a70b9b66-54dc-46ec-b81f-12531573fa38",
"status": "200"
}