1C-Bitrix Integration with UniSender
UniSender is one of the leading email marketing platforms with a straightforward REST API. It suits mid-sized businesses: affordable pricing, solid deliverability to major mail services (Mail.ru, Yandex.Mail).
UniSender API
All methods are available at https://api.unisender.com/ru/api/{method}?format=json&api_key={KEY}. Authentication uses an API key passed as a query parameter or request header. The key is created in the UniSender account settings.
Contact Synchronisation
class UniSenderClient {
private string $apiKey;
private string $baseUrl = 'https://api.unisender.com/ru/api/';
public function __construct() {
$this->apiKey = COption::GetOptionString('site', 'unisender_api_key');
}
public function importContacts(array $contacts, int $listId): array {
// Batch import of up to 500 contacts per call
$fieldNames = ['email', 'email_list_ids', 'Name', 'Phone'];
$fieldValues = [];
foreach ($contacts as $c) {
$fieldValues[] = [
$c['email'],
(string)$listId,
$c['name'] ?? '',
$c['phone'] ?? '',
];
}
$http = new \Bitrix\Main\Web\HttpClient();
return json_decode($http->post($this->baseUrl . 'importContacts', [
'api_key' => $this->apiKey,
'format' => 'json',
'field_names' => $fieldNames,
'data' => $fieldValues,
'overwrite_tags' => 1,
'overwrite_lists' => 0,
]), true);
}
}
importContacts is the primary method for bulk synchronisation. Each call handles up to 500 contacts. When exporting the full subscriber base, split it into batches.
Subscription Handler
AddEventHandler('subscribe', 'OnSubscribeSubscribe', function($id, $email, $fields) {
$listId = COption::GetOptionString('site', 'unisender_list_id');
$client = new UniSenderClient();
$client->subscribe($email, $listId, [
'Name' => $fields['NAME'] ?? '',
'Phone' => $fields['PERSONAL_PHONE'] ?? '',
]);
});
The subscribe method adds a single contact and sends them a confirmation email (double opt-in) if that setting is enabled in UniSender.
Retrieving Contact Status
Before creating a mailing it is useful to know the subscriber's current status — whether they are active or have unsubscribed:
public function getContactStatus(string $email): string {
$http = new \Bitrix\Main\Web\HttpClient();
$response = json_decode($http->get(
$this->baseUrl . 'getContact?api_key=' . $this->apiKey
. '&format=json&email=' . urlencode($email)
), true);
return $response['result']['status'] ?? 'unknown';
// 'active', 'unsubscribed', 'bounced', 'spam'
}
Used during order processing: if the buyer has unsubscribed, they are not added to new mailing lists.
Triggered Mailing After Order Placement
After an order is placed, a series of transactional emails is sent via UniSender Automation:
AddEventHandler('sale', 'OnSaleOrderSaved', function($order) {
if (!$order->isNew()) return;
$email = getOrderEmail($order);
// Send transactional email via UniSender
$client = new UniSenderClient();
$client->sendEmail([
'to' => [['email' => $email, 'name' => getOrderName($order)]],
'subject' => 'Order #' . $order->getId() . ' confirmed',
'body' => renderOrderEmailTemplate($order),
'list_id' => UNISENDER_TRANSACT_LIST_ID,
'sender_name' => 'Store',
'sender_email' => '[email protected]',
]);
});
Deliverability Analytics
UniSender provides statistics via getCampaignStatus and getCampaignCommonStats. Data is retrieved for each mailing and logged into a custom 1C-Bitrix info block for trend monitoring:
- Open rate, CTR, bounces, unsubscribes.
- If bounce rate exceeds 5%, the campaign is automatically paused and the marketing team is notified.
| Task | Effort |
|---|---|
| API client + subscription handlers | 3–5 h |
| Bulk subscriber base export | 3–4 h |
| Transactional emails on events | 4–6 h |
| Analytics collection in 1C-Bitrix | 3–4 h |







