SMS - API
Betatel's SMS API provides a powerful and reliable way to send messages instantly, ensuring seamless communication with your users. Whether you're sending transactional updates, promotional alerts, or authentication messages, our API is designed for speed, security, and global reach.
In this guide, weβll focus on one of the most common SMS use cases: sending OTP (One-Time Password) messages. OTPs are essential for user authentication, account verification, and secure transactions, ensuring that only authorized users can access sensitive data or complete actions.
Follow the steps below to integrate and send OTP messages using Betatelβs SMS API with ease. π
Configure the API Endpointβ
Start by preparing the endpoint URL for your request.
https://api.betatel.com/api/smpp/client/send
- Method:
POST
Set Up the Headersβ
Add the necessary headers for your API request:
Param | Value | Description |
---|---|---|
Content-type | application/json | Specifies the payload format. |
x-api-key | {{x-api-key} | API key for authorization. |
Craft the Request Bodyβ
Design the JSON payload to include the sender, recipient, and the message content.
{"from":"FACEBOOK", "to":"38761930305", "text":"Your code is 555345"}
Field | Type | Required | Description |
---|---|---|---|
from | string | Yes | The sender ID or name (e.g., "FACEBOOK"). |
to | string | Yes | The recipient's phone number in international format. |
text | string | Yes | The message content (e.g., "Your code is 555345"). |
Code Snippetsβ
Here's how to implement the API call in different programming languages:
- cUrl
- Python
- Node.js
- PHP
- Java
- C#
curl --location --globoff 'https:/api.betatel.com/api/smpp/client/send' \
--header 'Content-Type: application/json' \
--header 'x-api-key: β’β’β’β’β’β’' \
--data '{"from":"FACEBOOK", "to":"38761930305", "text":"Your code is 555345"}'
import http.client
import json
conn = http.client.HTTPSConnection("api.betatel.com")
payload = json.dumps({
"from": "FACEBOOK",
"to": "38761930305",
"text": "Your code is 555345"
})
headers = {
'Content-Type': 'application/json',
'x-api-key': 'β’β’β’β’β’β’'
}
conn.request("POST", "/api/smpp/client/send", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
const axios = require('axios');
let data = JSON.stringify({
"from": "FACEBOOK",
"to": "38761930305",
"text": "Your code is 555345"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.betatel.com/api/smpp/client/send',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'β’β’β’β’β’β’'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.betatel.com/api/smpp/client/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 =>'{"from":"FACEBOOK", "to":"38761930305", "text":"Your code is 555345"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'x-api-key: {{x-api-key-callgen}}'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.betatel.com/api/smpp/client/send")
.header("Content-Type", "application/json")
.header("x-api-key", "β’β’β’β’β’β’")
.body("{\"from\":\"FACEBOOK\", \"to\":\"38761930305\", \"text\":\"Your code is 555345\"}")
.asString();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.betatel.com/api/smpp/client/send");
request.Headers.Add("x-api-key", "β’β’β’β’β’β’");
var content = new StringContent("{\"from\":\"FACEBOOK\", \"to\":\"38761930305\", \"text\":\"Your code is 555345\"}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Understanding the Responseβ
Once the API processes your request, it returns a response containing a unique identifier for your message.
JSON Schema:
{
"uuid": "string"
}
uuid
: A unique string to track the delivery and status of your message.
Outbound Message status checkβ
Tracking Message Status in Real-Timeβ
Betatel's SMS API allows you to programmatically track message status changes via status callbacks. These status updates help you monitor message delivery and troubleshooting.
Status Lifecycleβ

When a message is sent, it transitions through multiple statuses:
Status | Description |
---|---|
queued | Message is queued for sending. |
sent | Message has been successfully sent. |
failed | Message failed to send. |
delivered | Message was successfully delivered to the recipient. |
undelivered | Message could not be delivered. |
read | Message was read (Only applicable to WhatsApp). |
Example Status Callback Payloadβ
When a status change occurs, Betatel will send an HTTP POST request to your configured status callback URL with the following payload:
JSON Schema:
{
"uuid": "e5b7c3f2-d8a6-4f6c-93b9-123456789abc",
"status": "delivered",
"to": "+38761930305",
"timestamp": "2025-02-03T12:34:56Z"
}
Field | Type | Description |
---|---|---|
uuid | string | Unique message identifier. |
status | string | The current status of the message. |
to | string | The recipient's phone number. |
timestamp | string (ISO 8601) | Time of status update. |
Congratulationsβ
Congratulations! You've successfully integrated Betatel's SMS API to send OTP messages with ease. This guide ensures that your implementation adheres to best practices and provides a seamless experience for both developers and end-users.