POST Send SMS
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/v1/connect-hub/sms
- 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. |
x-user-id | {{x-user-id}} | User identifier for added security and tracking. |
Craft the Request Body
Design the JSON payload to include the sender, recipient, and the message content.
{"from":"Sender", "to":"12345678548", "text":"Your code is 555345"}
Field | Type | Required | Description |
---|---|---|---|
from | string | Yes | The sender ID or name (e.g., "Sender"). |
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 'https://api.betatel.com/api/v1/connect-hub/sms' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-user-id: YOUR_USER_ID' \
--data '{
"from":"Sender",
"to":"12345678548",
"text": "Your code is 555345"
}'
import http.client
import json
conn = http.client.HTTPSConnection("api.betatel.com")
payload = json.dumps({
"from": "Sender",
"to": "12345678548",
"text": "Your code is 555345"
})
headers = {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY',
'x-user-id': 'YOUR_USER_ID'
}
conn.request("POST", "/api/v1/connect-hub/sms", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
const axios = require('axios');
let data = JSON.stringify({
"from": "Sender",
"to": "12345678548",
"text": "Your code is 555345"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.betatel.com/api/v1/connect-hub/sms',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY',
'x-user-id': 'YOUR_USER_ID'
},
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/v1/connect-hub/sms',
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":"Sender", "to":"12345678548", "text":"Your code is 555345"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'x-api-key: YOUR_API_KEY',
'x-user-id: YOUR_USER_ID'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://api.betatel.com/api/v1/connect-hub/sms")
.header("Content-Type", "application/json")
.header("x-api-key", "YOUR_API_KEY")
.header("x-user-id", "YOUR_USER_ID")
.body("{\"from\":\"Sender\", \"to\":\"12345678548\", \"text\":\"Your code is 555345\"}")
.asString();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.betatel.com/api/v1/connect-hub/sms");
request.Headers.Add("x-api-key", "YOUR_API_KEY");
request.Headers.Add("x-user-id", "YOUR_USER_ID");
var content = new StringContent("{\"from\":\"Sender\", \"to\":\"12345678548\", \"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:
{
"messageId": "0a62face-6d15-11f0-962f-d89d6729654c",
"from": "Sender",
"to": "38161444555"
}
messageId
: A unique string to track the delivery and status of your message.from
: The caller ID displayed to the recipient.to
: The recipient's phone number.
Error Handling
- 400 - Bad Request: Invalid parameters or malformed request
- 401 - Unauthorized: Authentication failed
- 500 - Internal Server Error: An unexpected error occurred on the server