Отправка Viber с текстом (JSON API)
Пример запроса для отправки Viber-сообщение с текстом на указанный номер.
URI: /api/json.php
Все запросы к API отправляются в формате JSON с помощью метода POST.
Параметры заголовков
В запросах обязательно должен быть заголовок Content-Type: application/json, иначе запрос будет считаться некорректным даже при валидном JSON в нем
Параметры запроса
Пример запроса
- JSON
- cURL
- PHP
- Python
- Node.js
{
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "viber",
"id": 100500,
"phone": 380971234567,
"viber_type": "text",
"viber_signature": "ViberTest",
"viber_message": "Message text to send via Viber",
"viber_lifetime": 172800,
"short_link": true,
"hook": "https://example.org/webhook/url.php"
}
]
}
curl -X POST 'https://alphasms.ua/api/json.php' \
-H 'Content-Type: application/json' \
--data-raw '{
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "viber",
"id": 100500,
"phone": 380971234567,
"viber_type": "text",
"viber_signature": "ViberTest",
"viber_message": "Message text to send via Viber",
"viber_lifetime": 172800,
"short_link": true,
"hook": "https://example.org/webhook/url.php"
}
]
}'
<?php
$payload = json_encode([
'auth' => 'bb56a4369eb19***cfec6d1776bd25',
'data' => [
[
'type' => 'viber',
'id' => 100500,
'phone' => 380971234567,
'viber_type' => 'text',
'viber_signature' => 'ViberTest',
'viber_message' => 'Message text to send via Viber',
'viber_lifetime' => 172800,
'short_link' => true,
'hook' => 'https://example.org/webhook/url.php',
],
],
], JSON_UNESCAPED_UNICODE);
$ch = curl_init('https://alphasms.ua/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": "viber",
"id": 100500,
"phone": 380971234567,
"viber_type": "text",
"viber_signature": "ViberTest",
"viber_message": "Message text to send via Viber",
"viber_lifetime": 172800,
"short_link": True,
"hook": "https://example.org/webhook/url.php",
},
],
}
response = requests.post(
"https://alphasms.ua/api/json.php",
json=payload,
timeout=30,
)
print(response.json())
const payload = {
"auth": "bb56a4369eb19***cfec6d1776bd25",
"data": [
{
"type": "viber",
"id": 100500,
"phone": 380971234567,
"viber_type": "text",
"viber_signature": "ViberTest",
"viber_message": "Message text to send via Viber",
"viber_lifetime": 172800,
"short_link": true,
"hook": "https://example.org/webhook/url.php"
}
]
};
const response = await fetch("https://alphasms.ua/api/json.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
console.log(await response.json());
Параметры ответа
| successinteger Результат выполнения запроса | |||||||
| errorstring Текст ошибки, который возвращается, если success=false | |||||||
| datalist[object] Список объектов с результатами выполнения запроса
|
Примеры ответа
- Успешный
- Доступ запрещен
- Ошибка в Альфа-имени
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": "Error in Alpha-name",
"data": {
"id": 100500
}
}
]
}