POST WhatsApp OTP
This endpoint sends a WhatsApp message containing a one-time password (OTP) or verification text to a specified phone number. The system dispatches the message through the WhatsApp Business API and returns a unique identifier that can be used to track the message status.
Configure the API Endpoint
https://api.betatel.com/api/v1/connect-hub/whatsapp/otp
- Method:
POST
Set Up the Headers
| Param | Value | Description |
|---|---|---|
| Content-type | application/json | Specifies the payload format. |
| x-api-key | {{x-api-key}} | API key for authorization. |
| x-account-id | {{x-account-id}} | User identifier for added security and tracking. |
Craft the Request Body
Design the JSON payload to include the recipient's phone number and the message text to be delivered.
{
"to": "38761444555",
"text": "482910"
}
| Field | Type | Required | Description |
|---|---|---|---|
| to | string | Yes | The recipient's phone number in E.164 format (without the + prefix). |
| text | string | Yes | The message text to be sent (maximum 4096 characters). |
Phone Number Formatting:
Provide the phone number without the + prefix. For example, use 38761444555 instead of +38761444555. The number must be a valid WhatsApp-registered phone number.
Code Snippets
- cUrl
- Python
- Node.js
- PHP
- Java
- C#
curl --location 'https://api.betatel.com/api/v1/connect-hub/whatsapp/otp' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-account-id: YOUR_ACCOUNT_ID' \
--data '{
"to": "38761444555",
"text": "482910"
}'
import http.client
import json
conn = http.client.HTTPSConnection("api.betatel.com")
payload = json.dumps({
"to": "38761444555",
"text": "482910"
})
headers = {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY',
'x-account-id': 'YOUR_ACCOUNT_ID'
}
conn.request("POST", "/api/v1/connect-hub/whatsapp/otp", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
const axios = require('axios');
let data = JSON.stringify({
"to": "38761444555",
"text": "482910"
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://api.betatel.com/api/v1/connect-hub/whatsapp/otp',
headers: {
'Content-Type': 'application/json',
'x-api-key': 'YOUR_API_KEY',
'x-account-id': 'YOUR_ACCOUNT_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/whatsapp/otp',
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 => '{"to":"38761444555","text":"482910"}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'x-api-key: YOUR_API_KEY',
'x-account-id: YOUR_ACCOUNT_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/whatsapp/otp")
.header("Content-Type", "application/json")
.header("x-api-key", "YOUR_API_KEY")
.header("x-account-id", "YOUR_ACCOUNT_ID")
.body("{\"to\":\"38761444555\",\"text\":\"482910\"}")
.asString();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.betatel.com/api/v1/connect-hub/whatsapp/otp");
request.Headers.Add("x-api-key", "YOUR_API_KEY");
request.Headers.Add("x-account-id", "YOUR_ACCOUNT_ID");
var content = new StringContent("{\"to\":\"38761444555\",\"text\":\"482910\"}", 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 the unique identifier for the message and the recipient's phone number.
JSON Schema:
{
"uuid": "01JV5V54KPYK9GB29265EQRZ2P",
"to": "38761444555"
}
uuid: The unique identifier for the WhatsApp message. Use this to track the message status.to: The recipient's phone number as provided in the request.
Message Status Lifecycle
After a message is sent, WhatsApp reports status updates through the webhook. A message progresses through the following states:
| Status | Description |
|---|---|
PENDING | Message accepted and queued for delivery. |
SENT | Message dispatched to the WhatsApp platform. |
DELIVERED | Message delivered to the recipient's device. |
READ | Recipient has opened and read the message. |
FAILED | Message could not be delivered. |
EXPIRED | Message expired before delivery was confirmed. |
Error Handling
- 400 - Bad Request: Invalid parameters or malformed request
- 401 - Unauthorized: Authentication failed
- 402 - Payment Required: Insufficient account balance
- 500 - Internal Server Error: An unexpected error occurred on the server