Sending OTPs
One of the primary use cases when using textly is verification & authentication, we provide an easy to use endpoint for dispatching OTPs to your user's phone numbers.
- TypeScript
- PHP (Laravel)
- Curl
- VB.NET
- c#
const myApiToken = await getApiToken(); // See authentication guide to learn how to get a token
const response = await fetch("https://api.textly.ly/api/v1/client/send_otp", {
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: `Bearer ${myApiToken}`,
}),
body: JSON.stringify({
target_number: "09100000",
wait_for_send: true,
}),
});
use Illuminate\Support\Facades\Http;
$token = getApiToken();
$response = Http::withHeaders([
"Authorization" => "Bearer $token"
])->post('https://api.textly.ly/api/v1/client/send_otp', [
"target_number" => "09100000",
"wait_for_send" => true,
]);
$ curl -X POST https://api.textly.ly/api/v1/client/send_otp \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR API TOKEN>" \
-d '{
"target_number": "09100000",
"wait_for_send": true
}'
' Required Imports
Imports System
Imports System.Net.Http
Imports System.Net.Http.Headers
Imports System.Text
Private Sub SendSms()
Using client As New HttpClient()
client.DefaultRequestHeaders.Authorization = New AuthenticationHeaderValue("Bearer", "<api-key>")
Dim requestBody As String = $"{{""target_number"":""<phone-number>"",""wait_for_send"":false}}"
Dim content As New StringContent(requestBody, Encoding.UTF8, "application/json")
Dim response As HttpResponseMessage = client.PostAsync("https://api.textly.ly/api/v1/client/send_otp", content).Result
Console.WriteLine(response.Content.ReadAsStringAsync().Result)
End Using
End Sub
using System.Net.Http.Headers;
using System.Text;
using System.Text.Json;
string token = "<your-api-key-here>";
using (HttpClient cl = new HttpClient())
{
cl.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
cl.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var requestBody = new
{
target_number = "<number1>",
wait_for_send = false
};
var json = JsonSerializer.Serialize(requestBody);
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await cl.PostAsync("https://api.textly.ly/api/v1/client/send_otp", content);
if (response.IsSuccessStatusCode)
{
Console.WriteLine("Message sent successfully.");
}
else
{
Console.WriteLine($"Error: {response.StatusCode}");
}
}
As we can see from the code snippet the /api/v1/client/send_otp
expects a json body that contains
{
"target_number": "09100000",
"wait_for_send": true
}
- target_number: is the number the OTP is going to be sent to
- wait_for_send: whether or not to immediately send the message or have it be scheduled to send 3 to 5 seconds (optional)