What it does
Pulls contacts from both Bitrix24 (via actions.v2.fetchList.make) and an external ERP (mocked in the recipe — replace with your client). Matches them by tax id (ufCrmInn) primarily and email as a fallback. Creates missing rows on each side and syncs changed name fields back to Bitrix24.
Stack
Node.js 18+, node-cron.
Install
pnpm add node-cron
Environment
export B24_HOOK='https://your.bitrix24.com/rest/1/secret'
Run
npx tsx 04-erp-sync.ts
Source
skills/b24jssdk-recipes/examples/04-erp-sync.ts.
Notes
- ERP-side functions (
fetchErpContacts,createErpContact,updateErpContact) are stubs. Plug in your client (1C OData, REST, etc.). - The matching key is
ufCrmInn— adjust the field name to whatever your custom-field namespace uses. - For thousands of contacts the per-row
createBitrixContactawait loop is the bottleneck. Replace it withactions.v2.batchByChunk.make({ calls: erpContacts.map((e) => ['crm.item.add', { entityTypeId: 3, fields: ... }]), options: { isHaltOnError: false } })— see recipe 5 (Disk files) for the basicbatch.makeshape and theb24jssdk-restskill forbatchByChunk.makedetails.