Sending SMS
Textly also allows you to send text messages to one or more targets which you can do by dispatching a post request to /api/v1/client/send_sms
- 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_sms", {
method: "POST",
headers: new Headers({
"Content-Type": "application/json",
Authorization: `Bearer ${myApiToken}`,
}),
body: JSON.stringify({
target_numbers: ["09100000"],
content: "Hello world",
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_sms', [
"target_numbers" => ["09100000"],
"content" => "Hello world"
"wait_for_send" => true,
]);
$ curl -X POST https://api.textly.ly/api/v1/client/send_sms \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <YOUR API TOKEN>" \
-d '{
"target_numbers": ["09100000"],
"content": "Hello world",
"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_numbers"":[""<phone-number>""],""content"":""test"",""wait_for_send"":true}}"
Dim content As New StringContent(requestBody, Encoding.UTF8, "application/json")
Dim response As HttpResponseMessage = client.PostAsync("https://api.textly.ly/api/v1/client/send_sms", 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_numbers = new[] { "<number1>", "<number2>" },
content = "Hello world",
};
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_sms", 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_sms
expects a json body that contains
{
"target_numbers": ["09100000"],
"content": "4501",
"wait_for_send": true
}
- Target_numbers: an array of phone numbers which the message will be sent to (must contain at least one number)
- content: is the content of the text message
- wait_for_send: whether or not to immediately send the message or have it be scheduled to send 3 to 5 seconds (optional)