Integration of 1C-Bitrix with Mindbox (Personalization)
Mindbox is a marketing automation platform: unified customer profile, segmentation, trigger campaigns, loyalty programs, personalized promo codes. Integration with Bitrix covers several directions: transmitting customer and order data, obtaining personalized offers for specific user, and managing loyalty program.
Integration Architecture
Mindbox works via REST API with two modes:
- Synchronous — request → response in real-time. Used on registration/auth (get customer profile, issue bonuses) and order checkout (apply discount from promo code, check bonus balance).
- Asynchronous — events queued and processed by Mindbox in background. Used for transmitting view data, cart adds, order history.
Bitrix → Mindbox API (events): registration, order, view
Mindbox → Bitrix (callback): bonus balance, promo status
Mindbox → Email/SMS: campaigns, triggers (Mindbox internal)
Mindbox API Authentication
Mindbox uses authorization via secret in header:
Authorization: Mindbox secretKey="YOUR_SECRET_KEY"
Content-Type: application/json
Base URL: https://api.mindbox.ru/v3/operations/async (async) and /v3/operations/sync (sync).
Registration Event Transmission
On user registration in Bitrix — event to Mindbox for creating/updating customer profile:
AddEventHandler('main', 'OnAfterUserRegister', function(&$arUser) {
sendMindboxEvent('Website.RegisterCustomer', [
'customer' => [
'email' => $arUser['EMAIL'],
'mobilePhone' => $arUser['PERSONAL_PHONE'] ?? '',
'firstName' => $arUser['NAME'] ?? '',
'lastName' => $arUser['LAST_NAME'] ?? '',
'customFields'=> [
'bitrixUserId' => $arUser['USER_ID'],
],
],
'executionDateTimeUtc' => gmdate('Y-m-d\TH:i:s\Z'),
]);
});
function sendMindboxEvent(string $operation, array $data, bool $sync = false): ?array
{
$endpoint = $sync
? 'https://api.mindbox.ru/v3/operations/sync'
: 'https://api.mindbox.ru/v3/operations/async';
$http = new \Bitrix\Main\Web\HttpClient();
$http->setHeader('Authorization', 'Mindbox secretKey="' . MINDBOX_SECRET . '"');
$http->setHeader('Content-Type', 'application/json');
$payload = array_merge(['deviceUUID' => getMindboxDeviceUUID()], $data);
$response = $http->post(
$endpoint . '?endpointId=' . MINDBOX_ENDPOINT_ID
. '&operation=' . urlencode($operation),
json_encode($payload)
);
return $sync ? json_decode($response, true) : null;
}
Order Transmission
On order creation in Bitrix, send full data:
AddEventHandler('sale', 'OnSaleOrderSaved', function(\Bitrix\Main\Event $event) {
$order = $event->getParameter('ENTITY');
$isNew = $event->getParameter('IS_NEW');
if (!$isNew) return;
$basket = $order->getBasket();
$lines = [];
foreach ($basket->getOrderableItems() as $item) {
$lines[] = [
'product' => [
'ids' => ['bitrix' => $item->getProductId()],
],
'count' => $item->getQuantity(),
'price' => $item->getPrice(),
'basePricePerItem' => $item->getBasePrice(),
];
}
sendMindboxEvent('Website.CreateOrder', [
'order' => [
'ids' => ['bitrix' => $order->getId()],
'totalPrice' => $order->getPrice(),
'discountedPrice' => $order->getPrice(),
'lines' => $lines,
],
'customer' => [
'email' => $order->getUserEmail(),
'ids' => ['bitrixId' => $order->getUserId()],
],
]);
});
Bonus Program: Check and Apply
Synchronous request on checkout — get bonus balance and apply:
function getMindboxBonusBalance(int $userId): float
{
$user = CUser::GetByID($userId)->Fetch();
$result = sendMindboxEvent('Website.GetCustomerBalance', [
'customer' => ['email' => $user['EMAIL']],
], true);
return (float)($result['customer']['bonusPointsBalance']['available'] ?? 0);
}
function applyMindboxBonuses(int $orderId, int $userId, float $bonusAmount): bool
{
$user = CUser::GetByID($userId)->Fetch();
$result = sendMindboxEvent('Website.ConfirmOrderBonusPoints', [
'order' => ['ids' => ['bitrix' => $orderId]],
'customer' => ['email' => $user['EMAIL']],
'payment' => ['bonusPoints' => $bonusAmount],
], true);
return ($result['status'] ?? '') === 'Success';
}
On checkout page, bonus balance is requested via AJAX and shown to user with ability to apply part or all.
Personalized Promo Codes
Mindbox generates personal promo codes for each segment. On checkout, verify promo code:
function validateMindboxPromocode(string $code, int $userId): ?array
{
$user = CUser::GetByID($userId)->Fetch();
$result = sendMindboxEvent('Website.CheckPromocode', [
'order' => ['promocode' => $code],
'customer' => ['email' => $user['EMAIL']],
], true);
if (($result['status'] ?? '') !== 'Success') {
return null;
}
return [
'discount_type' => $result['order']['discountType'] ?? 'percent',
'discount_value' => $result['order']['discountValue'] ?? 0,
];
}
Returned discount type and value are used for cart recalculation via Bitrix discount mechanism or directly via $item->setField('DISCOUNT_PRICE', ...).
DeviceUUID
Mindbox links anonymous actions and authorized user via device UUID:
function getMindboxDeviceUUID(): string
{
if (!isset($_COOKIE['mindboxDeviceUUID'])) {
$uuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
setcookie('mindboxDeviceUUID', $uuid, time() + 86400 * 365, '/');
return $uuid;
}
return $_COOKIE['mindboxDeviceUUID'];
}
Mindbox JavaScript tracker also reads this UUID and automatically links site behavior.
JS Tracker Connection
<!-- In footer.php or via addExternalJs -->
<script>
var mindbox = window.mindbox || [];
mindbox.push = mindbox.push || function(e) { mindbox.queue.push(e); };
mindbox.queue = mindbox.queue || [];
mindbox('create', {
endpointId: '<?= MINDBOX_ENDPOINT_ID ?>'
});
</script>
<script src="https://api.mindbox.ru/scripts/v1/tracker.js" async></script>
Implementation Timeline
| Scope | Components | Timeline |
|---|---|---|
| Basic (registration + orders + JS tracker) | Event handlers + API client | 3–5 days |
| Loyalty program (balance + apply) | Sync requests + cart form | +3–5 days |
| Full (promo codes + segments + personalization) | Complete integration + scenario testing | 2–3 weeks |







