Send Batch Triggered Viber message
The Send Triggered Viber message method allows sending bulk Viber messages to contacts added to our system and saved to a list, but no more than 100 contacts at a time. The Viber messages are sent from the domain where the list was created, using templates previously created and saved within our system.
IMPORTANT: In a single request, you can send communications to no more than 100 contacts at once.
Request
IMPORTANT: Do not send more than 10 concurrent API requests.
Body Example
{
"templateId": "YOUR_TEMPLATE_ID",
"contactListId": "YOUR_CONTACT_LIST_ID",
"contacts": [
{
"contact": "contact1Identifier",
"variables": [
{
"name": "contactVar",
"value": "contactVarValue"
}
]
},
{
"contact": "contact2Identifier"
},
{
"contact": "contact3Identifier"
}
],
"variables": [
{
"name": "templateVar",
"value": "templateVarValue"
}
],
"tag": [
"YOUR_BATCH_TAGS",
],
"device": "all",
"senderId": "YOUR_SENDER_ID",
"ttl": 3600,
}
Parameters
Title | Type | Default | Description |
---|---|---|---|
contactListId required
|
string |
ID of the contact list which the contact belongs to. |
|
contacts required
|
array |
An array of objects that includes the contacts identifiers to which the messages will be sent, as well as an array of objects with unique variables for each contact. |
|
contacts.contact required
|
string |
The |
|
contacts.variables optional
|
array |
An array of unique variables for each contact. Please, take in account variables usage priorities is case of conflicting variables:
Important! Variables passed to the contact have the highest priority when used in the template. |
|
contacts.variables.name required
|
string |
The name of the contact's unique variable.
|
|
contacts.variables.value required
|
string|integer|boolean |
The value of the contact's unique variable. Variable value in |
|
templateId required
|
string |
The Push template you want to send. The template should be already created in your account on the Templates page: |
|
tags optional
|
array |
An array of strings that can be used to tag a message. Statistics are accumulated using tags, and the number of tags available depends on the plan. All tags you want to use must be created in advance on the platform in the tags section. Tags should be 50 characters or less. Any tags starting with an underscore are reserved for internal use and will cause errors. |
|
variables optional
|
array |
An array of common variables that will be applied to the sending for each individual recipient. Please, take in account variables usage priorities is case of conflicting variables:
|
|
variables.name required
|
string |
The name of the variable that will be applied in the template for each contact.
|
|
variables.value required
|
string|integer|boolean |
The value of the variable that will be applied in the template for each contact. Variable value in |
|
device optional
|
string | 3600 |
Add kind of devices to the parameter:
|
senderId optional
|
string |
Your own registered name in Viber. |
|
ttl optional
|
integer |
Time to live must be specified in seconds. Between 30 minutes to 72 hour. |
Response
{
"result": true,
"success": {
"contactIdentifier": "Message ID"
},
"failed": {
"contactIdentifier": "Error description"
}
}
Parameters
Title | Type | Description |
---|---|---|
result |
boolean |
Indicated that the query was successful or not:
|
success |
object |
An object containing all successful sends, including the contacts identifiers to whom the emails were sent and the |
success.contactIdentifier |
string |
The identifiers of the contact to whom the successful send was made. |
success[messageId] |
string |
The Message ID of a successful send to a specific contact. |
failed |
object |
An object with failed sends, including the contact identifiers that could not receive the communication and the reason why the send was unsuccessful. |
failed.contactIdentifier |
string |
The identifiers of the contact to whom the communication could not be sent. |
failed[error] |
string |
The error that prevented the sending to a specific contact. |
Method Errors
{
"result": false,
"errors": [
"Error description"
]
}
Error |
---|
"Argument contactListId must be a string" |
"Argument contactListId must be a non-empty string" |
"Contact list with id {contactListId} not found" |
"Each contact must contain contact field" |
"Argument contacts must be an array of objects" |
"Amount of contacts must be less or equal 100" |
"No contacts to handle" |
"Duplicated as {contact}", |
"Contact not found" |
"name of variable can not be empty" |
"Argument templateId must be a non-empty string" |
"Template with id {templateId} not found" |
"Argument tags must be an array" |
"Tag name must be a non-empty string" |
"Tags should be 50 characters or less" |
"Any tags starting with an underscore are reserved for internal use and will cause errors" |
"Argument variables must be an array of arrays with \"name\" and \"value\" fields" |
"name of variable must be a string" |
"variable \"{name}\" is reserved and can not be added as custom variable" |
"invalid name of variable {name}" |
"Payment required" |
"Twig syntax error: {error}" |
"Invalid authorization token!" |
"Internal server error" |
"Bad Request" |
"no matches found for access token {accessToken}" |
"user {id} not enabled" |
"no data found for key {userId}" |
"access token check failed for key/secret $key/$accessToken" |
"Argument {argument} required" |
"Argument device must be a non-empty string" |
"Argument device must be in [all, phone]" |
"Argument senderId must be a non-empty string" |
"There is no registered senderId {id} in account" |
"Sender with senderId {id} not registered in account" |
"Sender with senderId {id} not approved" |
"Country of contact is not allowed for senderId {id}" |
"No default senderId registered for country" |
"Argument ttl must be a positive integer" |
"Template {id} is rejected" |
"Template {id} is not approved" |
"Template {id} is not allowed to use in restricted country" |
"Contact is not active" |
"Tag %s is not registered in account tags" |
Code Examples
$accessToken = 'YOUR_API_KEY';
$url = 'https://api.wooxy.com/v3/viber/batch';
$body = json_encode([
'templateId' => 'YOUR_TEMPLATE_ID',
'contactListId' => 'YOUR_CONTACT_LIST_ID',
'contacts' => [
[
'contact' => 'contact1Identifier',
'variables' => [
[
'name' => 'contactVar',
'value' => 'contactVarValue'
]
]
],
[
'contact' => 'contact2Identifier'
],
[
'contact' => 'contact3Identifier'
]
],
'variables' => [
[
'name' => 'templateVar',
'value' => 'templateVarValue'
]
],
'tag' => [
'YOUR_BATCH_TAGS',
],
'device' => 'all',
'senderId' => 'YOUR_SENDER_ID',
'ttl' => 3600,
]);
/** * Request Example */
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_INFILESIZE, null);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Access-Token: $accessToken",
'Content-Type: application/json',
'Content-Length: ' . strlen($body),
]);
$result = curl_exec($ch);
if ($result === false) {
echo 'cURL error:' . curl_error($ch) . PHP_EOL;
} else {
echo strval($result) . PHP_EOL;
}
curl_close($ch);