OTP [GET/POST]: Send OTP to a Phone Number
End Point
https://otp.ng/api/otp/
Submit OTP requests to the end point. All the requests are submitted through HTTPS POST/GET method. Although you can use HTTP protocol, we strongly recommend you to submit all requests to API over HTTPS so the traffic is encrypted and the privacy is ensured.
SENDING OTP PARAMETERS
Parameter | Type | Description |
---|---|---|
apikey | String | The unique string to authenticate request. Generate, validate and manage apikeys API Tokens |
to | String | The phone number to receive the OTP |
from | String | Alphanumeric identifier of the message. Also refer to as the Sender ID |
otp | String | The OTP code to be sent to be sent to the phone number |
template_id | Integer | The message template to be used with the OTP. The combination of the template content and the OTP above forms the message. Create and manage OTP templates at Templates |
ref_id | String | Optional. Unique code to identify the OTP from your application generally used for delivery tracking |
OTP Request Format (HTTPS POST Method)
Sample Code to send OTP Request through HTTPS POST call to the OTP API
<?php
$endpoint = 'https://otp.ng/api/otp/';
$otpArray = array (
'otp'=> 'OTP_CODE_HERE',
'apikey' => 'API_KEY_HERE',
'to' =>'PHONE_NUMBER_HERE',
'from' =>'SENDER_ID_HERE',
'template_id'=>'TEMPLATE_ID_HERE',
'ref_id'=>'REF_ID_HERE'
);
$params = http_build_query($otpArray);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch); curl_close($ch);
echo $response; // response code
?>
OTP Request Format (HTTPS GET Method)
Snippet to send SMS to a single number through HTTPS GET call to the API
<?php
$endpoint = 'https://otp.ng/api/otp/';
$otp_array = array ( 'otp'=> 'OTP_CODE_HERE', 'apikey' => 'API_KEY_HERE', 'to' =>'PHONE_NUMBER_HERE', 'from' =>'SENDER_ID_HERE',
);
'template_id'=>'TEMPLATE_ID_HERE',
'ref_id'=>'REF_ID_HERE'
$push = $endpoint.'?'.http_build_query($otp_array);
$response = file_get_contents($push);
echo $response;
?>
OTP Response Format
All response are in the format below:
{json data}
Possible Response Codes
On Success
{
"success": "true",
"msg_id": "xxxx",
"ref_id": "yyyy",
"comment": "zzzz",
}
Parameters | Type | Description |
success | Boolean | Sets to true |
msg_id | String | OTP.NG unique id for the message |
ref_id | String | The specified ref_id is returned for confirmation |
comment | String | Additional comment, if any. |
On Failure
{
"success": "false",
"comment": "Reson for error",
}
Parameters | Type | Description |
success | Boolean | Sets to false |
comment | String | Description for failure |