Send OTP Code (WhatsApp)
An example of a request to send a one-time password (OTP) via WhatsApp.
WhatsApp is not a message type of its own. A request with type: whatsapp is rejected with the error Invalid message type.
WhatsApp exists only as a stage of a pipeline: you send a request of type: pipeline and list whatsapp among its stages. Everything else — the endpoint, the key, the response format — is the same as for any other JSON API method.
URI: https://alphasms.net/api/json.php
All requests to API are sent in JSON format using the POST method.
Header parameters
Requests must contain header Content-Type: application/json, otherwise, the request will be considered invalid even if it has valid JSON.
Request parameters
Request example
- JSON
- cURL
- PHP
- Python
- Node.js
{
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "pipeline",
"pipeline": [
"whatsapp"
],
"id": 100500,
"phone": 380971234567,
"whatsapp": {
"signature": "SenderID",
"message": "Your code is 1234"
}
}
]
}
curl -X POST 'https://alphasms.net/api/json.php' \
-H 'Content-Type: application/json' \
--data-raw '{
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "pipeline",
"pipeline": [
"whatsapp"
],
"id": 100500,
"phone": 380971234567,
"whatsapp": {
"signature": "SenderID",
"message": "Your code is 1234"
}
}
]
}'
<?php
$payload = json_encode([
'auth' => 'bb56a4369eb19***cfec6d1776bd25',
'data' => [
[
'type' => 'pipeline',
'pipeline' => [
'whatsapp',
],
'id' => 100500,
'phone' => 380971234567,
'whatsapp' => [
'signature' => 'SenderID',
'message' => 'Your code is 1234',
],
],
],
], JSON_UNESCAPED_UNICODE);
$ch = curl_init('https://alphasms.net/api/json.php');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => $payload,
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
import requests
payload = {
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "pipeline",
"pipeline": [
"whatsapp",
],
"id": 100500,
"phone": 380971234567,
"whatsapp": {
"signature": "SenderID",
"message": "Your code is 1234",
},
},
],
}
response = requests.post(
"https://alphasms.net/api/json.php",
json=payload,
timeout=30,
)
print(response.json())
const payload = {
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "pipeline",
"pipeline": [
"whatsapp"
],
"id": 100500,
"phone": 380971234567,
"whatsapp": {
"signature": "SenderID",
"message": "Your code is 1234"
}
}
]
};
const response = await fetch("https://alphasms.net/api/json.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
console.log(await response.json());
Response parameters
| successboolean Result of request execution | ||||
| errorstring Error text, returned if success=false | ||||
| datalist[object] List of objects with the results of request execution
|
Response examples
- Successful
- No route
- Wrong type
- Access denied
HTTP Status Code: 200
Content Type: JSON application/json
{
"success": true,
"data": [
{
"success": true,
"data": {
"msg_id": 123456789
}
}
]
}
WhatsApp is not enabled on your route, or there is no route for the operator of that number.
HTTP Status Code: 200
Content Type: JSON application/json
{
"success": true,
"data": [
{
"success": false,
"error": "No route"
}
]
}
The answer to type: whatsapp. WhatsApp is a pipeline stage, not a message type.
HTTP Status Code: 200
Content Type: JSON application/json
{
"success": false,
"error": "Invalid message type"
}
HTTP Status Code: 200
Content Type: JSON application/json
{
"success": false,
"error": "Access denied"
}
Fallback to another channel. List the channels in the order you want them tried and add the parameters of each stage. The gateway charges the most expensive stage up front and returns the difference once the message is actually delivered.
{
"type": "pipeline",
"pipeline": ["whatsapp", "sms"],
"id": 100500,
"phone": 380971234567,
"whatsapp": { "signature": "SenderID", "message": "Your code is 1234" },
"sms": { "signature": "SenderID", "message": "Your code is 1234" }
}
The full list of stages and their parameters is on the Multi channel page.
WhatsApp has to be enabled on your route — the gateway and the price are set by your manager. Without them any pipeline containing whatsapp answers with No route.
The whatsapp stage is not validated by the API. If signature or message is missing, the request is still accepted and charged, and the message goes out empty. Check both fields on your side before sending.
The delivery status of a pipeline request goes to the notification address from your API settings — see Delivery report by URL: the gateway does not store hook for this type.