UA API
Search
K
Links
Comment on page

VIBER API

DecisionTelecom Viber API дозволяє надсилати та отримувати ділові повідомлення Viber у будь-яку країну світу та з неї через API. Кожне повідомлення ідентифікується унікальним випадковим ідентифікатором, тому користувачі можуть перевірити статус повідомлення, використовуючи задану кінцеву точку.
Viber API використовує HTTPS з ключем доступу, який використовується як авторизація API. Корисні дані запитів та відповідей форматуються як JSON за допомогою кодування UTF-8.
API Авторизація - Базовий ключ доступу Base64.
Щоб отримати ключ API, будь ласка, зв'яжіться з вашим менеджером по роботі з клієнтами.

Авторизація

Базова авторизація

Example:

$userHashKey = 'User Hash Key provided by your account manager';
$ch = curl_init('https://web.it-decision.com/v1/api/send-viber');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$userHashKey");
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestParams)); //
$requestParams - raquest array with correct data
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$result = curl_exec($ch);
curl_close($ch);

Надіслати Вайбер повідомлення

POST
https://web.it-decision.com/v1/api/send-viber
Request POST:
{
"source_addr": "Custom Company",
"destination_addr": 8882222200,
"message_type":106,
"text":"Message content",
"image":"https://yourdomain.com/images/image.jpg",
"button_caption":"Join Us",
"button_action":"https://yourdomain.com/join-us",
"source_type":1,
"callback_url":"https://yourdomain.com/viber-callback",
"validity_period":3600
}

Параметри

source_addr:
<= 20 chars - from whom the message
destination_addr:
<= 20 chars - to whom the message
message_type (Type of message sent):
106 only text (convenient for transactional messages)
108 text+image+button (convenient for promotional messages)
206 only text (2Way)*(convenient for promotional messages)
208 text+image+button (2Way)* (convenient for promotional messages)
text:
<= 1000 chars - text of Viber message
image (Correct URL with image for promotional message with button caption and button action):
jpg or jpeg (mime type is image/jpeg), maximum resolution 400x400 pixels
png (mime type is image/png), maximum resolution 400x400 pixels
button_caption:
<= 30 chars - button caption
button_action:
Correct URL for transition when you press the button
source_type (Message sending procedure):
promotion message (the message can be with text, picture and button) - 1
transactional message (text message) – 2
callback_url:
Correct URL for message status callback
validity_period:
TTL (Time to live) allows the sender to limit the lifetime of a message. In case the message did not get the status "delivered" before the time ended, the message will not be charged and will not be delivered to the user. In case no TTL was provided (no "ttl" parameter) Viber will try to deliver the message for up to 1 day.
promotion message - min TTL 40 seconds max TTL 21600 seconds (6 hours)
transactional message - min TTL 40 seconds max TTL 21600 seconds (6 hours)

Response:

JSON (POST)
{
"message_id":429
}

Values:

message_id:
Sent message ID

Get message from a user for 2Way messages:

For 2way messages ITD Viber system will send callbacks with each user's message. The tracking data content will be sent by the client according to the tracking data in the last message which was received on the Viber client’s side.
The response implies that the API user has a callback url for this message.

Response:

JSON (POST):
{
"message_token": 44444444444444,
"phone_number": "972512222222",
"time": 2121212121,
"message":
{
"text": "a message to the service",
"tracking_data": "tracking_id:100035"
}
}

Значення

message_token:
client response message token
phone_number:
client phone number
time:
client response message time
message:
text:
client response message text
tracking_data:
tracking_id: The id of the message to which the client is responding

Отримати Вайбер повідомлення

POST
https://web.it-decision.com/v1/api/receive-viber
Request POST:
{
"message_id":429
}

Параметри

message_id:
The ID of the message whose status you want to get (for the last 5 days)
Response JSON:
{
"message_id":429,
"status":1,
}

Значення

message_id:
The ID of the message whose status you want to get (for the last 5 days)
status:
Current Viber message status

Статуси повідомлень Вайбер

sent
0
delivered
1
error
2
rejected
3
undelivered
4
pending
5
seen
6
unknown
20

Помилки

Name
Too Many Requests
message
Rate limit exceeded
code
0
status
429
Name
Invalid Parameter: [param_name]
message
Empty parameter or parameter validation error
code
1
status
400
Name
Internal server error
message
The server encountered an unexpected condition which prevented it
from fulfilling the request
code
2
status
500
Name
Topup balance is required
message
User balance is empty
code
3
status
402

Приклад Вайбер

cUrl
С#
Golang
Java
JavaScript
C – lib cUrl
NodeJs
PHP
Python
Ruby
curl --location --request POST 'https://web.it-decision.com/v1/api/send-viber' \
--header 'Authorization: Basic api key' \
--header 'Content-Type: application/json' \
--data-raw '{"source_addr": "Custom Company", "destination_addr": 8882222200,"message_type":106,"text":"Message content","image":"https://yourdomain.com/images/image.jpg","button_caption":"Join Us","button_action":"https://yourdomain.com/join-us","source_type":1,"callback_url":"https://yourdomain.com/viber-callback","validity_period":3600}'
var client = new RestClient("https://web.it-decision.com/v1/api/send-viber");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Basic api key");
request.AddHeader("Content-Type", "application/json");
var body = @"{""source_addr"": ""Custom Company"", ""destination_addr"": 8882222200,""message_type"":106,""text"":""Message content"",""image"":""https://yourdomain.com/images/image.jpg"",""button_caption"":""Join Us"",""button_action"":""https://yourdomain.com/join-us"",""source_type"":1,""callback_url"":""https://yourdomain.com/viber-callback"",""validity_period"":3600}";
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://web.it-decision.com/v1/api/send-viber"
method := "POST"
payload := strings.NewReader(`{"source_addr": "Custom Company", "destination_addr": 8882222200,"message_type":106,"text":"Message content","image":"https://yourdomain.com/images/image.jpg","button_caption":"Join Us","button_action":"https://yourdomain.com/join-us","source_type":1,"callback_url":"https://yourdomain.com/viber-callback","validity_period":3600}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Authorization", "Basic api key")
req.Header.Add("Content-Type", "application/json")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"source_addr\": \"Custom Company\", \"destination_addr\": 8882222200,\"message_type\":106,\"text\":\"Message content\",\"image\":\"https://yourdomain.com/images/image.jpg\",\"button_caption\":\"Join Us\",\"button_action\":\"https://yourdomain.com/join-us\",\"source_type\":1,\"callback_url\":\"https://yourdomain.com/viber-callback\",\"validity_period\":3600}");
Request request = new Request.Builder()
.url("https://web.it-decision.com/v1/api/send-viber")
.method("POST", body)
.addHeader("Authorization", "Basic api key")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
var myHeaders = new Headers();
myHeaders.append("Authorization", "Basic api key");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"source_addr": "Custom Company",
"destination_addr": 8882222200,
"message_type": 106,
"text": "Message content",
"image": "https://yourdomain.com/images/image.jpg",
"button_caption": "Join Us",
"button_action": "https://yourdomain.com/join-us",
"source_type": 1,
"callback_url": "https://yourdomain.com/viber-callback",
"validity_period": 3600
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://web.it-decision.com/v1/api/send-viber", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://web.it-decision.com/v1/api/send-viber");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Authorization: Basic api key");
headers = curl_slist_append(headers, "Content-Type: application/json");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
const char *data = "{\"source_addr\": \"Custom Company\", \"destination_addr\": 8882222200,\"message_type\":106,\"text\":\"Message content\",\"image\":\"https://yourdomain.com/images/image.jpg\",\"button_caption\":\"Join Us\",\"button_action\":\"https://yourdomain.com/join-us\",\"source_type\":1,\"callback_url\":\"https://yourdomain.com/viber-callback\",\"validity_period\":3600}";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
res = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
var https = require('follow-redirects').https;
var fs = require('fs');
var options = {
'method': 'POST',
'hostname': 'web.it-decision.com',
'path': '/v1/api/send-viber',
'headers': {
'Authorization': 'Basic api key',
'Content-Type': 'application/json'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = JSON.stringify({
"source_addr": "Custom Company",
"destination_addr": 8882222200,
"message_type": 106,
"text": "Message content",
"image": "https://yourdomain.com/images/image.jpg",
"button_caption": "Join Us",
"button_action": "https://yourdomain.com/join-us",
"source_type": 1,
"callback_url": "https://yourdomain.com/viber-callback",
"validity_period": 3600
});
req.write(postData);
req.end();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://web.it-decision.com/v1/api/send-viber',
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 =>'{"source_addr": "Custom Company", "destination_addr": 8882222200,"message_type":106,"text":"Message content","image":"https://yourdomain.com/images/image.jpg","button_caption":"Join Us","button_action":"https://yourdomain.com/join-us","source_type":1,"callback_url":"https://yourdomain.com/viber-callback","validity_period":3600}',
CURLOPT_HTTPHEADER => array(
'Authorization: Basic api key',
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
import http.client
import json
conn = http.client.HTTPSConnection("web.it-decision.com")
payload = json.dumps({
"source_addr": "Custom Company",
"destination_addr": 8882222200,
"message_type": 106,
"text": "Message content",
"image": "https://yourdomain.com/images/image.jpg",
"button_caption": "Join Us",
"button_action": "https://yourdomain.com/join-us",
"source_type": 1,
"callback_url": "https://yourdomain.com/viber-callback",
"validity_period": 3600
})
headers = {
'Authorization': 'Basic api key',
'Content-Type': 'application/json'
}
conn.request("POST", "/v1/api/send-viber", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
require "uri"
require "json"
require "net/http"
url = URI("https://web.it-decision.com/v1/api/send-viber")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = "Basic api key"
request["Content-Type"] = "application/json"
request.body = JSON.dump({
"source_addr": "Custom Company",
"destination_addr": 8882222200,
"message_type": 106,
"text": "Message content",
"image": "https://yourdomain.com/images/image.jpg",
"button_caption": "Join Us",
"button_action": "https://yourdomain.com/join-us",
"source_type": 1,
"callback_url": "https://yourdomain.com/viber-callback",
"validity_period": 3600
})
response = https.request(request)
puts response.read_body