DEV Community

ZoomApps
ZoomApps

Posted on

Migrating from amoCRM to Bitrix24: mapping pipelines, fields and history

Moving a sales team from amoCRM to Bitrix24 looks like an export and an import. Both systems have deals, contacts, companies, tasks and notes, both have REST APIs, and the first test run usually finishes in an evening. Then someone opens a deal in Bitrix24 and finds it has no contact, the stage is "New" for a deal that was won two years ago, every record says it was created last Tuesday, and the phone numbers no longer match the format your telephony expects.

This post walks through the parts of a migration script that decide whether the data arrives usable: the order of operations, how to map pipelines and custom fields, how to keep relations and history, and how to prove the result with numbers. Method names and limits match the public documentation of both APIs at the time of writing. Check them against the current docs before you run anything against production.

The shape of the job

A reliable migration is a repeatable script, not a one-shot import. You will run it several times against a test Bitrix24 portal, fix what broke, and run it again until the reconciliation matches. That changes how you design it:

  1. Extract everything from amoCRM into a local store (SQLite or PostgreSQL is fine). Never transform while reading from the API.
  2. Transform in the local store: map stages, fields, users, clean duplicates.
  3. Load into Bitrix24 in dependency order, writing every created ID back to a mapping table.
  4. Reconcile: count records and relations on both sides and print the differences.

The local store is what makes the process restartable. If the load crashes at deal 14,000 of 30,000, you resume from the mapping table instead of starting over and creating duplicates.

Extracting from amoCRM

amoCRM API v4 exposes the entities you need under predictable paths:

GET /api/v4/leads?with=contacts,catalog_elements&limit=250&page=1
GET /api/v4/contacts?with=leads&limit=250
GET /api/v4/companies?limit=250
GET /api/v4/tasks?limit=250
GET /api/v4/leads/notes?limit=250
GET /api/v4/leads/pipelines
GET /api/v4/leads/custom_fields
GET /api/v4/users
Enter fullscreen mode Exit fullscreen mode

A few things to plan around:

  • Pagination. limit tops out at 250. Follow _links.next until it disappears instead of computing page counts yourself, because records can be added while you read.
  • Rate limit. The documented ceiling is a handful of requests per second per integration, and exceeding it returns HTTP 429. Repeated violations can get the integration blocked for a while. A token bucket at 5 requests per second with exponential backoff on 429 keeps you safe.
  • Relations come from with. A lead does not include its contacts unless you ask for with=contacts. The _embedded.contacts array also tells you which contact is the main one (is_main), which you need later.
  • Notes are per entity type. Leads, contacts and companies each have their own notes endpoint. Note types (common, call_in, call_out, service_message and so on) carry different params payloads, so store the raw JSON and decide on rendering later.
  • Empty responses. An empty page comes back as HTTP 204 with no body, not as an empty JSON array. Code that blindly parses the body will crash on the last page of a small entity.

Store everything raw, keyed by amoCRM ID, with the full JSON in a column. You will come back to fields you did not think you needed.

Mapping pipelines and stages

amoCRM pipelines map to Bitrix24 deal categories (funnels), and stages map to category statuses. In Bitrix24 the modern way to list and create funnels is crm.category.list and crm.category.add with entityTypeId: 2 for deals. Stages live in crm.status.list with ENTITY_ID set to DEAL_STAGE for the default funnel and DEAL_STAGE_<categoryId> for the others.

Do not try to generate the target funnels automatically from the old ones. In practice the amoCRM pipelines have drifted: stages nobody uses, two stages that mean the same thing, a "Thinking" stage that became a graveyard. Agree on the target funnels with the sales lead first, set them up in Bitrix24 by hand, and then write an explicit mapping table:

# stage_map.yaml
pipelines:
  4521873:            # amoCRM "Retail"
    category_id: 0    # Bitrix24 default funnel
    stages:
      42154398: NEW
      42154401: PREPARATION
      42154404: PREPAYMENT_INVOICE
      142: WON          # amoCRM "Closed - won"
      143: LOSE         # amoCRM "Closed - lost"
  4521880:            # amoCRM "Wholesale"
    category_id: 3
    stages:
      42154510: C3:NEW
      42154513: C3:EXECUTING
      142: C3:WON
      143: C3:LOSE
Enter fullscreen mode Exit fullscreen mode

Two details here cause most stage bugs. First, amoCRM uses the fixed status IDs 142 and 143 for won and lost in every pipeline, so the mapping has to be per pipeline, not global. Second, stage IDs in non-default Bitrix24 funnels are prefixed with C<categoryId>:. If you pass WON for a deal in category 3, Bitrix24 will either reject it or put the deal somewhere you did not intend.

Make the script fail loudly on any amoCRM status that is missing from the map. A silent fallback to the first stage is how two years of closed deals end up as new leads.

Mapping custom fields

amoCRM custom field values arrive as an array:

"custom_fields_values": [
  {
    "field_id": 512341,
    "field_name": "Source",
    "field_type": "select",
    "values": [{ "value": "Instagram", "enum_id": 801233 }]
  }
]
Enter fullscreen mode Exit fullscreen mode

In Bitrix24 custom fields are user fields with names like UF_CRM_1700000000, created through crm.deal.userfield.add (and the contact and company equivalents). List options get their own IDs, so a select field needs a two-level map: field to field, and enum to enum.

amoCRM type Bitrix24 type Notes
text, textarea string Keep line breaks, they survive as-is
numeric double amoCRM may return numbers as strings
select, radiobutton enumeration Map every enum_id to a Bitrix24 list item ID
multiselect enumeration with MULTIPLE: Y Send an array
checkbox boolean
date, date_time date, datetime amoCRM sends Unix timestamps
url url or string
multitext (phone, email) standard PHONE, EMAIL Not a user field, see below

This is also the moment to drop fields. A typical amoCRM account collects dozens of fields over the years, and a quick query on your local store shows how many records actually have each one filled:

SELECT f.field_name,
       COUNT(*) AS filled
FROM lead_field_values f
GROUP BY f.field_name
ORDER BY filled ASC;
Enter fullscreen mode Exit fullscreen mode

Fields filled on a few dozen records out of thousands are candidates for deletion or for folding into a note. Some fields also duplicate standard Bitrix24 features (source, responsible person, expected close date) and should map to the built in fields instead of becoming user fields.

Phones and emails deserve special attention. In amoCRM they are multitext custom fields with enum codes like WORK or MOB. In Bitrix24 they are the multi-fields PHONE and EMAIL:

"PHONE": [
  { "VALUE": "+77011234567", "VALUE_TYPE": "MOBILE" },
  { "VALUE": "+77272345678", "VALUE_TYPE": "WORK" }
]
Enter fullscreen mode Exit fullscreen mode

Normalize numbers to E.164 during the transform step. Telephony matching and duplicate search in Bitrix24 both depend on it, and a mix of 8 701..., +7 (701) and 701... will quietly break caller identification later.

Users and ownership

Every record has a responsible user. Build a user map from /api/v4/users to Bitrix24 user IDs by email, and decide in advance what happens to records owned by people who have left. Usually they go to a sales manager or a dedicated "archive" user. If the map is missing a user, stop the run: assigning thousands of deals to the admin who ran the script is a common and annoying cleanup job.

Load order and relations

Relations only survive if parents exist before children. The order that works:

  1. Companies (crm.company.add)
  2. Contacts (crm.contact.add), then bind them to companies (crm.contact.company.items.set)
  3. Deals (crm.deal.add with CATEGORY_ID, STAGE_ID, COMPANY_ID)
  4. Deal contacts (crm.deal.contact.items.set, marking the amoCRM main contact as IS_PRIMARY: Y)
  5. Tasks, linked to CRM entities through UF_CRM_TASK with values like D_123 or C_456
  6. Notes and files into the timeline

Every successful call writes a row to the mapping table, in the same transaction as marking the source record as loaded:

def load_deal(db, b24, amo_lead):
    if db.mapped_id("deal", amo_lead["id"]):
        return  # already loaded, safe to rerun
    fields = transform_deal(db, amo_lead)
    new_id = b24.call("crm.deal.add", {"fields": fields})["result"]
    db.save_mapping("deal", amo_lead["id"], new_id)
Enter fullscreen mode Exit fullscreen mode

Bitrix24 REST has its own limits: roughly two requests per second on standard plans with a short burst allowance, and batch lets you send up to 50 commands in one request. Batch is the difference between a migration that takes a night and one that takes a week. Keep in mind that a batch is not a transaction. Some commands can succeed while others fail, so parse result_error for each command and record successes individually.

History: what moves and how

Two kinds of history behave differently.

Creation and modification dates. DATE_CREATE on a deal is set by Bitrix24 and cannot be written through crm.deal.add. If reporting by original creation date matters (it usually does for sales analytics), store the amoCRM created_at and closed_at in user fields such as UF_CRM_AMO_CREATED, and build reports on those. Decide this before the first test run, because adding it later means updating every record.

Notes and calls. Text notes go into the timeline through crm.timeline.comment.add with ENTITY_TYPE and ENTITY_ID. The comment will show the migration date, so prefix the body with the original date and author:

[amoCRM, 2024-03-14 11:02, Aigerim S.]
Client asked for a revised quote with delivery to Shymkent.
Enter fullscreen mode Exit fullscreen mode

Call notes carry a link to the recording and a duration. You can render them as comments with the link, or download the recordings and attach them as files. The second option is heavier but survives the day the old amoCRM account is closed and the links stop working.

Files attached to notes need to be downloaded from amoCRM and re-uploaded. Plan the disk space and the time: this step is often slower than all the record creation combined.

Chat history from connected messengers is the least predictable part. Whether it can be exported at all depends on how the channel was connected and where the conversation was stored, so check it on real records during the audit rather than promising it upfront.

Reconciliation

A migration is finished when the numbers match, not when the script exits with code 0. Run a reconciliation report after every test load:

entity            amoCRM   Bitrix24   diff
companies          4,812      4,812      0
contacts          18,330     18,327     -3
deals             29,604     29,604      0
deal-contact      31,118     31,102    -16
tasks             52,940     52,940      0
timeline notes    88,415     88,409     -6
Enter fullscreen mode Exit fullscreen mode

Count relations, not just records. Sixteen missing deal-contact links in the example above means sixteen deals that a manager will open and find empty. Each difference should be explainable by a rule (a deliberately dropped duplicate, a contact without any data) or treated as a bug. Spot check a few dozen records by hand as well: pick old won deals, deals with many contacts, and records with files.

Cutover

The final transfer needs a window when nobody is editing amoCRM. With a tested, restartable script that is usually a weekend:

  • Friday evening: freeze amoCRM (read only for managers), run the full extract.
  • Saturday: load and reconcile.
  • Sunday: spot checks, re-point integrations (site forms, telephony, messengers) to Bitrix24.
  • Monday: the team works in the new system.

If the freeze is impossible, run a full load a few days early and then a delta load filtered by filter[updated_at][from] during the window. The mapping table makes this safe: updated records are updated, new ones are created.

Plan for the parts that will not move. Custom amoCRM widgets and some automations have no direct equivalent and need to be rebuilt as Bitrix24 robots, business processes or a small app. Find them during the audit and agree on replacements before the cutover, not after.

If you would rather hand the audit, test transfers and cutover to a team that runs this process regularly, here is how we approach moving a sales team from amoCRM to Bitrix24.

Top comments (0)