Skip to content

VIBER

Sending

To send a Viber message it is required to call POST /viber/messages sending message parameters in the body with authorization data in the heading.

Request parameters

Parameter Data type Description
from string The sender’s name used when sending the message
Only the senders’ names which are available for using by the user.
to string Phone number in the international format in accordance with E. 164 standard
text
(optional)
string The message text, up to 1000 UTF-8 symbols
image
(optional)
string URL to the image, supported image formats:
- JPG
- JPEG
- PNG
action
(optional)
string URL the user will be forwarded to after having clicked on the button
Any valid URL including direct links of mobile operating systems
caption
(optional)
string The button text, up to 30 UTF-8 symbols
validity
(optional)
integer Lifetime of the message in seconds
Minimum value: 15
Maximum value: 1209600, 14 days
Default value: 86400, 1 day
priority
(optional)
priority Message priority level
Between 0 and 3, where:
- 0 — low priority
- 3 — highest priority
- 0 — default priority level
scheduledTime
(optional)
string UTC time when the message is to be sent
Format: YYYY-MM-DD hh:mm:ss
callbackUrl
(optional)
string URL the system will send notifications on the message status changes to
Any valid HHTTP or HTTPS URL
options
(optional)
array[object] An array of optional data to be transmitted with the callback.
Any {“key1”: “value1”,“key2”: “value2” } array

Possible combinations of text, buttons and images

Though the parameters text, action, caption and image are considered optional in the description, it is necessary to specify at least one of them or more according to the following list of possible combinations:

  • text
  • text, action, caption
  • text, action, caption, image
  • action, caption, image

Request example

POST /messages
Authorization: Key QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Content-Type: application/json
Accept: application/json
{
    "messages":[
            {
                "from": "MyCompany",
                "to": "79034567890",
                "text": "Code: 1234",
                "image": "https://cdn.mycompany.com/viber.png",
                "action": "https://mycompany.com/promo",
                "caption": "Activate!"
            }
        ]   
}
curl -X POST \
 -H 'Authorization: Key QWxhZGRpbjpvcGVuIHNlc2FtZQ==' \
 -H 'Content-Type: application/json' \
 -d '{ 
    "messages": [
        {
            "from": "MyCompany",
            "to": "79034567890",
            "text": "Code: 1234",
            "image": "https://cdn.mycompany.com/viber.png",
            "action": "https://mycompany.com/promo",
            "caption": "Activate!"
        }
    ]   
}' https://api.devino.online/viber/messages
import requests

messages = {
    'messages': [
        {
            'from': 'MyCompany',
            'to': '79034567890',
            'text': 'Code: 1234',
            'image': 'https://cdn.mycompany.com/viber.png',
            'action': 'https://mycompany.com/promo',
            'caption': 'Activate!'
        }
    ]
}

resp = requests.post(
    'https://api.devino.online/viber/messages',
    json=messages
)
print(resp.json())

Response example

{
    "result": [
        {
            "code": "OK",
            "messageId": "3482512350952730368"
        }
    ]
}
{
    "result": [
        {
            "code": "string",
            "reasons": [
                {
                    "key": "string",
                    "ref": "string"
                }
            ],
            "messageId": "string"
        }
    ]
}

Response parameters

Parameter Data type Description
code string Points out the result of message processing
1. OK - Processed successfully
2. REJECTED - An error has occurred while processing the request
reasons
(optional)
Array[String, String] An array of the errors which occurred while processing the message
To be given with code=REJECTED only
reasons.key string Error code
reasons.ref string A reference to the parameter where the error occurred
messageId
(optional)
string Message ID
To be given with code=OK only

Receiving the status

While creating the message status a POST request will be sent to the URL provided when sending the message in the callbackUrl parameter. 200 OK is expected as the answer to the request.

In case the answer to the request is 500 Internal Error, there will be made 5 attempts to deliver the status with 1 minute interval.

Request example

{ 
    "messageId": "string",
    "status": "string",
    "ts": 0,
    "errorCode": 0,
    "ip": "string",
    "browser": "string",
    "os": "string",
    "userAgent": "string",
    "options": { }
}

Request parameters

Parameter Data type Status Description
messageId long any A unique message ID on the platform
ts int any Points out the time for creating the ‘status’ object
status enum any Delivery status code for the Viber message
For more information see Possible statuses
errorCode
(optional)
int rejected
undeliverable
Reason for non-delivery of the message to the user (status = undelivered)
- user_blocked – the user has been blocked;
- not_viber_user – the recipient is not a Viber user;
- message_limit_exceeded - the message limit has been exceeded for this name
ip
(optional)
string clicked
seen
The user’s IP
browser
(optional)
string clicked
seen
The user’s browser
os
(optional)
string clicked
seen
The user’s operating system
userAgent
(optional)
string any The user data the user wants to receive with the callback

Possible statuses

Parameter Description
scheduled The message has been scheduled.
enroute The message is in the queue for sending.
sent The message has been sent to the operator network.
delivered The message has been delivered to the user.
expired The lifetime of the message has expired.
seen The message has been read
clicked The link in the notification has been followed
undeliverable Unable to deliver the message.
rejected The message has been rejected by the operator or Devino.
deleted The message has been deleted from the queue for sending.
unknown An unknown error has occurred.
subscribed The user has subscribed
unsubscribed The user has unsubscribed