Setting up automatic lead import from Yandex.Direct to Bitrix24

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages

Setting Up Automatic Lead Import from Yandex Direct into Bitrix24

Leads from Yandex Direct lead forms accumulate in the Direct dashboard or in Yandex Metrica — and stay there. Until a manager manually logs in and transfers the data to the CRM, the lead sits unprocessed. The consequences are clear: response time drops and some submissions are lost during manual transfer. Automatic import removes the human from this chain.

Integration mechanism

Yandex Direct provides two ways to receive leads: the Leads API for Direct lead forms and a webhook configured on the lead form. For Bitrix24, the webhook approach is used — Yandex sends a POST request to the specified URL immediately when a form is submitted.

Step 1. In the Direct dashboard (Tools → Lead Forms), set the webhook URL in the form settings:

https://your-server.com/webhook/yandex-direct-leads

Step 2. The webhook handler creates a lead in Bitrix24 via the REST API:

// webhook/yandex-direct-leads.php
$rawBody = file_get_contents('php://input');
$data    = json_decode($rawBody, true);

// Signature verification (HMAC-SHA256)
$signature = hash_hmac('sha256', $rawBody, YANDEX_WEBHOOK_SECRET);
if ($signature !== $_SERVER['HTTP_X_YANDEX_SIGN'] ?? '') {
    http_response_code(403);
    exit;
}

// Mapping Direct form fields to Bitrix24 lead fields
$leadData = [
    'TITLE'      => 'Lead from Yandex Direct: ' . ($data['campaign_name'] ?? ''),
    'NAME'       => $data['answers']['name']  ?? '',
    'PHONE'      => [['VALUE' => $data['answers']['phone'] ?? '', 'VALUE_TYPE' => 'WORK']],
    'EMAIL'      => [['VALUE' => $data['answers']['email'] ?? '', 'VALUE_TYPE' => 'WORK']],
    'SOURCE_ID'  => 'ADVERTISEMENT',
    'SOURCE_DESCRIPTION' => 'Yandex Direct',
    // UTM tags from form parameters
    'UF_CRM_UTM_SOURCE'   => $data['utm_source']   ?? 'yandex',
    'UF_CRM_UTM_MEDIUM'   => $data['utm_medium']   ?? 'cpc',
    'UF_CRM_UTM_CAMPAIGN' => $data['utm_campaign'] ?? $data['campaign_id'] ?? '',
    'UF_CRM_UTM_TERM'     => $data['utm_term']     ?? '',
    'UF_CRM_AD_ID'        => $data['ad_id']        ?? '',
    'UF_CRM_CAMPAIGN_ID'  => $data['campaign_id']  ?? '',
];

// Submit to Bitrix24
$b24 = new BitrixWebhookClient(B24_WEBHOOK_URL);
$result = $b24->call('crm.lead.add', ['FIELDS' => $leadData, 'PARAMS' => ['REGISTER_SONET_EVENT' => 'Y']]);

Alternative: Yandex Direct Leads API

If the lead form does not support webhooks (legacy forms) — use polling via the Yandex Direct API:

// Cron every 5 minutes: check for new leads
public function importNewLeads(): void
{
    $token = YANDEX_OAUTH_TOKEN;
    $lastImportTime = $this->getLastImportTime(); // from Redis/file

    $response = $this->yandexApiRequest('GetLeads', [
        'SelectionCriteria' => [
            'DateTimeRange' => [
                'From' => $lastImportTime->format('Y-m-d\TH:i:sP'),
                'To'   => (new DateTime())->format('Y-m-d\TH:i:sP'),
            ],
        ],
    ]);

    foreach ($response['Leads'] as $lead) {
        if (!$this->isAlreadyImported($lead['LeadId'])) {
            $this->createLeadInBitrix24($lead);
            $this->markAsImported($lead['LeadId']);
        }
    }

    $this->saveLastImportTime(new DateTime());
}

Idempotency is critical — the same lead must not be created in the CRM twice. Store already-imported IDs in a database table or Redis.

Lead assignment

After a lead is created, it is automatically assigned to a responsible manager via Bitrix24 pipeline robots and triggers, or via REST at creation time:

'ASSIGNED_BY_ID' => $this->getResponsibleManager($data['campaign_id']),

The mapping from a Direct campaign to a manager is stored in a configuration file or in custom settings within Bitrix24.

Deduplication

If a user submits the form twice, a duplicate lead will be created. Basic deduplication: before creating a lead, check whether a lead with the same phone number exists within the last 24 hours:

$existing = $b24->call('crm.lead.list', [
    'filter' => ['PHONE' => $phone, '>=DATE_CREATE' => date('Y-m-d', strtotime('-1 day'))],
    'select' => ['ID'],
]);

if (!empty($existing)) {
    // Add a comment to the existing lead instead of creating a duplicate
    $b24->call('crm.timeline.comment.add', [
        'ENTITY_TYPE' => 'lead',
        'ENTITY_ID'   => $existing[0]['ID'],
        'COMMENT'     => 'Repeat submission from Yandex Direct: ' . $data['campaign_name'],
    ]);
    return;
}

Scope of work

  • Webhook configuration in the Direct dashboard or Leads API setup (OAuth, polling)
  • Handler development: verification, field mapping, lead creation in Bitrix24
  • Storing UTM tags and campaign parameters in custom fields
  • Deduplication by phone/email
  • Automatic lead assignment
  • Testing on live forms, error logging

Timeline: 3–5 days with existing infrastructure. 1–2 weeks including custom Bitrix24 field setup and assignment rules.