Send a Viber campaign

Viber Campaigns help you to attract and communicate with customers through our Viber channel at a competitive cost.
Messages can be personal, informative, transactional, or promotional, and support text, images, buttons, and links.

In order to use Viber Campaign Service, you must first request for activation. Fill out the Viber Application Form and one of our representatives will get back to you as soon as possible to give you all the necessary information about the activation process.

You can submit the Viber Application Form here

The following example shows how easy is to send a Viber campaign using Routee API.

Your Header should contain authorization and content type:

KEYVALUE
Authorization:Bearer {access_token}
Content-Type:application/json

Request body contains the viber message (body), the senderInfoTrackingId (from), the recipient (to), the campaign name and the ttl.

The "senderInfoTrackingId" is unique and can be retrieved from Routee Platform. The Applications page contains all the information you need.

An example request is shown below:

curl --request POST \
  --url https://connect.routee.net/viber/campaign \
  --header 'authorization: Bearer 12dc9ff4-7df4-4786-8e7a-a46d317687f4' \
  --header 'content-type: application/json' \
  --header 'Expect:' \
  --data '{
    "senderInfoTrackingId": "YourRegisteredSenderId",
    "to": ["+3069xxxxxxxx"],
    "campaignName": "name of campaign",
        "body": {
        "text": "This is a viber message!",
        "imageURL": "http://via.placeholder.com/400x400",
        "action": {
            "targetUrl": "http://via.placeholder.com/400x400",
            "caption": "Go"
        }
        },
        "ttl": 5000,
    "callbackUrl": "http://www.YOURSERVER.COM/callback",
    "inboundUrl": "http://www.YOURSERVER.COM/inbound-messages"
    }'
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{ \n \"senderInfoTrackingId\": \"xxxx\",\n \"to\": [\"+3069xxxxxxxx\"],\n \"body\": {\n   \"text\": \"This is a viber message!\",\n   \"imageURL\": \"http://www.xxxx\",\n   \"action\": {\n   \t  \"targetUrl\": \"https://www.xxxx\",\n   \t  \"caption\": \"Go\"\n   \t}\n },\n \"ttl\": 5000\n}");
Request request = new Request.Builder()
  .url("https://connect.routee.net/viber/campaign")
  .post(body)
  .addHeader("content-type", "application/json")
  .addHeader("authorization", "Bearer 04c41869-f630-4f29-965d-c2ecdb397df0")
  .build();

Response response = client.newCall(request).execute();
var client = new RestClient("https://connect.routee.net/viber/campaign");
var request = new RestRequest(Method.POST);
request.AddHeader("authorization", "Bearer 04c41869-f630-4f29-965d-c2ecdb397df0");
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{ \n \"senderInfoTrackingId\": \"xxxx\",\n \"to\": [\"+3069xxxxxxxx\"],\n \"body\": {\n   \"text\": \"This is a viber message!\",\n   \"imageURL\": \"http://www.xxxx\",\n   \"action\": {\n   \t  \"targetUrl\": \"https://www.xxxx\",\n   \t  \"caption\": \"Go\"\n   \t}\n },\n \"ttl\": 5000\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://connect.routee.net/viber/campaign",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{ \n \"senderInfoTrackingId\": \"xxxxx\",\n \"to\": [\"+3069xxxxxxxx\"],\n \"body\": {\n   \"text\": \"This is a viber message!\",\n   \"imageURL\": \"http://www.xxxx\",\n   \"action\": {\n   \t  \"targetUrl\": \"https://www.xxxx\",\n   \t  \"caption\": \"Go\"\n   \t}\n },\n \"ttl\": 5000\n}",
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer 04c41869-f630-4f29-965d-c2ecdb397df0",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
import http.client

conn = http.client.HTTPSConnection("connect.routee.net")

payload = "{ \n \"senderInfoTrackingId\": \"xxxxx\",\n \"to\": [\"+3069xxxxxxxx\"],\n \"body\": {\n   \"text\": \"This is a viber message!\",,\n   \"imageURL\": \"http://www.xxxx\",\n   \"action\": {\n   \t  \"targetUrl\": \"https://www.xxxx\",\n   \t  \"caption\": \"Go\"\n   \t}\n },\n \"ttl\": 5000\n}"

headers = {
    'content-type': "application/json",
    'authorization': "Bearer 04c41869-f630-4f29-965d-c2ecdb397df0"
    }

conn.request("POST", "/viber/campaign", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'uri'
require 'net/http'

url = URI("https://connect.routee.net/viber/campaign")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request["authorization"] = 'Bearer 04c41869-f630-4f29-965d-c2ecdb397df0'
request.body = "{ \n \"senderInfoTrackingId\": \"xxxxx\",\n \"to\": [\"+3069xxxxxxxx\"],\n \"body\": {\n   \"text\": \"This is a viber message!\",\n   \"imageURL\": \"http://www.xxxx\",\n   \"action\": {\n   \t  \"targetUrl\": \"https://www.xxxx\",\n   \t  \"caption\": \"Go\"\n   \t}\n },\n \"ttl\": 5000\n}"

response = http.request(request)
puts response.read_body
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://connect.routee.net/viber/campaign",
  "method": "POST",
  "headers": {
    "content-type": "application/json",
    "authorization": "Bearer 04c41869-f630-4f29-965d-c2ecdb397df0"
  },
  "processData": false,
  "data": "{ \n \"senderInfoTrackingId\": \"xxxxx\",\n \"to\": [\"+3069xxxxxxxx\"],\n \"body\": {\n   \"text\": \"This is a viber message!\",\n   \"imageURL\": \"http://www.xxxx\",\n   \"action\": {\n   \t  \"targetUrl\": \"https://www.xxxx\",\n   \t  \"caption\": \"Go\"\n   \t}\n },\n \"ttl\": 5000\n}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
#import <Foundation/Foundation.h>

NSDictionary *headers = @{ @"content-type": @"application/json",
                           @"authorization": @"Bearer 04c41869-f630-4f29-965d-c2ecdb397df0"};
NSDictionary *parameters = @{ @"senderInfoTrackingId": @"xxxxx",
                              @"to": @[ @"+3069xxxxxxxx" ],
                              @"body": @{ @"text": @"This is a viber message!",  @"imageURL": @"http://www.xxxxxx", @"action": @{ @"targetUrl": @"https://www.xxxxxx", @"caption": @"Go" } },
                              @"ttl": @5000 };

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://connect.routee.net/viber/campaign"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

That's it! You have send a Viber campaign with Text, Image and Button.

To get more information for sending Viber campaigns check out our Resource Reference


What’s Next