Send OTP Code (WhatsApp)
A one-time code goes to WhatsApp with an authentication template. Meta writes its text itself — “1234 is your verification code” in the language of the template — and the code fills both the text and the copy button. Create such a template in your cabinet with the category Authentication.
A free-form text with a code reaches the subscriber only within 24 hours after their last message, so a code has to go with a template. A pipeline request with a whatsapp stage sends free-form text — it works only inside that window, see Multi channel.
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": "whatsapp",
"id": 100500,
"phone": 447700900123,
"whatsapp_signature": "WhatsAppTest",
"whatsapp_template": "login_code",
"whatsapp_code": "481516",
"hook": "https://example.org/webhook/url.php"
}
]
}
curl -X POST 'https://alphasms.net/api/json.php' \
-H 'Content-Type: application/json' \
--data-raw '{
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "whatsapp",
"id": 100500,
"phone": 447700900123,
"whatsapp_signature": "WhatsAppTest",
"whatsapp_template": "login_code",
"whatsapp_code": "481516",
"hook": "https://example.org/webhook/url.php"
}
]
}'
<?php
$payload = json_encode([
'auth' => 'bb56a4369eb19***cfec6d1776bd25',
'data' => [
[
'type' => 'whatsapp',
'id' => 100500,
'phone' => 447700900123,
'whatsapp_signature' => 'WhatsAppTest',
'whatsapp_template' => 'login_code',
'whatsapp_code' => '481516',
'hook' => 'https://example.org/webhook/url.php',
],
],
], 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": "whatsapp",
"id": 100500,
"phone": 447700900123,
"whatsapp_signature": "WhatsAppTest",
"whatsapp_template": "login_code",
"whatsapp_code": "481516",
"hook": "https://example.org/webhook/url.php",
},
],
}
response = requests.post(
"https://alphasms.net/api/json.php",
json=payload,
timeout=30,
)
print(response.json())
const payload = {
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "whatsapp",
"id": 100500,
"phone": 447700900123,
"whatsapp_signature": "WhatsAppTest",
"whatsapp_template": "login_code",
"whatsapp_code": "481516",
"hook": "https://example.org/webhook/url.php"
}
]
};
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
- Access denied
- No code
HTTP Status Code: 200
Content Type: JSON application/json
{
"success": true,
"data": [
{
"success": true,
"data": {
"id": 100500,
"msg_id": 123456789,
"data": 1,
"parts": 1
}
}
]
}
HTTP Status Code: 200
Content Type: JSON application/json
{
"success": false,
"error": "Access denied"
}
HTTP Status Code: 200
Content Type: JSON application/json
{
"success": true,
"data": [
{
"success": false,
"error": "WhatsApp authentication template needs a code",
"data": {
"id": 100500
}
}
]
}
Code with an SMS fallback
- JSON
- cURL
- PHP
- Python
- Node.js
{
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "whatsapp+sms",
"id": 100501,
"phone": 447700900123,
"whatsapp_signature": "WhatsAppTest",
"whatsapp_template": "login_code",
"whatsapp_code": "481516",
"sms_signature": "SMSTest",
"sms_message": "Your code is 481516",
"hook": "https://example.org/webhook/url.php"
}
]
}
curl -X POST 'https://alphasms.net/api/json.php' \
-H 'Content-Type: application/json' \
--data-raw '{
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "whatsapp+sms",
"id": 100501,
"phone": 447700900123,
"whatsapp_signature": "WhatsAppTest",
"whatsapp_template": "login_code",
"whatsapp_code": "481516",
"sms_signature": "SMSTest",
"sms_message": "Your code is 481516",
"hook": "https://example.org/webhook/url.php"
}
]
}'
<?php
$payload = json_encode([
'auth' => 'bb56a4369eb19***cfec6d1776bd25',
'data' => [
[
'type' => 'whatsapp+sms',
'id' => 100501,
'phone' => 447700900123,
'whatsapp_signature' => 'WhatsAppTest',
'whatsapp_template' => 'login_code',
'whatsapp_code' => '481516',
'sms_signature' => 'SMSTest',
'sms_message' => 'Your code is 481516',
'hook' => 'https://example.org/webhook/url.php',
],
],
], 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": "whatsapp+sms",
"id": 100501,
"phone": 447700900123,
"whatsapp_signature": "WhatsAppTest",
"whatsapp_template": "login_code",
"whatsapp_code": "481516",
"sms_signature": "SMSTest",
"sms_message": "Your code is 481516",
"hook": "https://example.org/webhook/url.php",
},
],
}
response = requests.post(
"https://alphasms.net/api/json.php",
json=payload,
timeout=30,
)
print(response.json())
const payload = {
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "whatsapp+sms",
"id": 100501,
"phone": 447700900123,
"whatsapp_signature": "WhatsAppTest",
"whatsapp_template": "login_code",
"whatsapp_code": "481516",
"sms_signature": "SMSTest",
"sms_message": "Your code is 481516",
"hook": "https://example.org/webhook/url.php"
}
]
};
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());