Send and Verify OTP
Send OTP
This API feature will give you the ability to send OTP SMS messages to single receiver using the same API. All API's accept GET and POST requests.
The base URL to use for this service is https://otp.libyasms.com/. The base URL cannot be used on its own; you must append a path that identifies an operation and you may have to specify some path parameters as well.
Parameters
| Parameter | Value | Required |
|---|---|---|
| apikey | apikey provided by Libya SMS | Yes |
| secretkey | secretkey provided by Libya SMS | Yes |
| callerID | your approved sender id | Yes |
| toUser | Receiver phone numbers including country code without + or 00, for example 218915063556 |
Yes |
| length | Integer number represent the length of the OTP code, it should be between 4 and 8 |
Yes |
| appSignature | Optional your application signature code for OTP autofill |
No |
| validityInSeconds | Optional OTP validity in seconds, default value 300 seconds |
No |
Request
Dim URL ="https://otp.libyasms.com/sendotp?apikey=7969ea24f713e424&secretkey=c7fba893&callerID=LibyaSMS&toUser=218915063556&length=6&appSignature=abdc1234&validityInSeconds=300"
Try
Dim request as WebRequest = WebRequest.Create(URL)
Dim response As WebResponse = request.GetResponse()
Dim dataStream As Stream = response.GetResponseStream()
Dim SR As New StreamReader(dataStream)
Dim str As String
str = SR.ReadToEnd()
Console.WriteLine(str)
response.Close()
Catch ex As System.Net.WebException
Console.WriteLine(ex.Message)
End Try
var client = new RestClient("https://otp.libyasms.com/sendotp?apikey=7969ea24f713e424&secretkey=c7fba893&callerID=LibyaSMS&toUser=218915063556&length=6&appSignature=abdc1234&validityInSeconds=300");
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
var request = http.Request('GET', Uri.parse('https://otp.libyasms.com/sendotp?apikey=7969ea24f713e424&secretkey=c7fba893&callerID=LibyaSMS&toUser=218915063556&length=6&appSignature=abdc1234&validityInSeconds=300'));
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://otp.libyasms.com/sendotp?apikey=7969ea24f713e424&secretkey=c7fba893&callerID=LibyaSMS&toUser=218915063556&length=6&appSignature=abdc1234&validityInSeconds=300',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://otp.libyasms.com/sendotp?apikey=7969ea24f713e424&secretkey=c7fba893&callerID=LibyaSMS&toUser=218915063556&length=6&appSignature=abdc1234&validityInSeconds=300")
.method("GET", body)
.build();
Response response = client.newCall(request).execute();
import http.client
conn = http.client.HTTPSConnection("otp.libyasms.com", 443)
payload = ''
headers = {}
conn.request("GET", "/sendotp?apikey=7969ea24f713e424&secretkey=c7fba893&callerID=LibyaSMS&toUser=218915063556&length=6&appSignature=abdc1234&validityInSeconds=300", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
require "uri"
require "net/http"
url = URI("https://otp.libyasms.com/sendotp?apikey=7969ea24f713e424&secretkey=c7fba893&callerID=LibyaSMS&toUser=218915063556&length=6&appSignature=abdc1234&validityInSeconds=300")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
response = https.request(request)
puts response.read_body
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)
var request = URLRequest(url: URL(string: "https://otp.libyasms.com/sendotp?apikey=7969ea24f713e424&secretkey=c7fba893&callerID=LibyaSMS&toUser=218915063556&length=6&appSignature=abdc1234&validityInSeconds=300")!,timeoutInterval: Double.infinity)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()
Response
Verify OTP
This API feature will give you the ability to verify OTP code the same API.
The base URL to use for this service is https://otp.libyasms.com/. The base URL cannot be used on its own; you must append a path that identifies an operation and you may have to specify some path parameters as well.
Parameters
| Parameter | Value | Required |
|---|---|---|
| otpId | Id received from send OTP API | Yes |
| otpCode | OTP code to be verified | Yes |
Request
Dim URL ="https://otp.libyasms.com/verify?otpId=0383729c-1d09-4226-8531-aecc8a883b0f&otpCode=614823"
Try
Dim request as WebRequest = WebRequest.Create(URL)
Dim response As WebResponse = request.GetResponse()
Dim dataStream As Stream = response.GetResponseStream()
Dim SR As New StreamReader(dataStream)
Dim str As String
str = SR.ReadToEnd()
Console.WriteLine(str)
response.Close()
Catch ex As System.Net.WebException
Console.WriteLine(ex.Message)
End Try
var request = http.Request('GET', Uri.parse('https://otp.libyasms.com/verify?otpId=0383729c-1d09-4226-8531-aecc8a883b0f&otpCode=614823'));
http.StreamedResponse response = await request.send();
if (response.statusCode == 200) {
print(await response.stream.bytesToString());
}
else {
print(response.reasonPhrase);
}
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://otp.libyasms.com/verify?otpId=0383729c-1d09-4226-8531-aecc8a883b0f&otpCode=614823',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("text/plain");
RequestBody body = RequestBody.create(mediaType, "");
Request request = new Request.Builder()
.url("https://otp.libyasms.com/verify?otpId=0383729c-1d09-4226-8531-aecc8a883b0f&otpCode=614823")
.method("GET", body)
.build();
Response response = client.newCall(request).execute();
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
var semaphore = DispatchSemaphore (value: 0)
var request = URLRequest(url: URL(string: "https://otp.libyasms.com/verify?otpId=0383729c-1d09-4226-8531-aecc8a883b0f&otpCode=614823")!,timeoutInterval: Double.infinity)
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
semaphore.signal()
return
}
print(String(data: data, encoding: .utf8)!)
semaphore.signal()
}
task.resume()
semaphore.wait()