Introducing a new way to review your PRs.

Read the announcement

frappe / crm

Fully featured, open source CRM

View on GitHub

24 documents · Updated Nov 23, 2026

docs / external-business-integrations

External business integrations

External business integrations connect CRM to systems that support sales work outside the CRM. They keep selected business records aligned with ERPNext, bring new prospects from Facebook lead forms into the CRM lead pipeline, and connect CRM calling with external telephony services.

Integration model

The repository uses three integration patterns. ERPNext provides a linked business record system for products, customers, quotations, and sales work. Facebook acts as a lead source whose form answers become CRM lead data. Telephony services carry calls while CRM keeps the call activity and links it to sales records.

These patterns have different ownership rules:

  • ERPNext synchronization keeps related records and access rules aligned across CRM and ERPNext.
  • Facebook lead ingestion moves new lead submissions into CRM. The CRM lead becomes the record used by the sales process.
  • Telephony integrations connect incoming and outgoing calls to CRM users and call records. The call record can point to the related lead, deal, or contact.

The integration settings and source records control whether work runs in the background or on demand. Telephony settings also control provider access, agent routing, and call recording. This keeps external requests separate from the main user flow and gives each source a saved sync point.

External system flows

This diagram shows how business records move between CRM and ERPNext, how new lead data enters CRM from Facebook, and how calls return to CRM as activity.

flowchart LR
    FB[Facebook lead form] -->|mapped submissions| Lead[CRM Lead]
    Lead --> Pipeline[CRM sales pipeline]
    CRM[CRM records] <-->|linked records and access| ERP[ERPNext]
    Deal[CRM Deal] -->|customer and quotation actions| ERP
    CRM -->|call setup and routing| Tel[External telephony]
    Tel -->|events and recording links| Call[CRM Call Log]
    Call -->|lead, deal, or contact link| CRM

The ERPNext path can use ERPNext on the same site as CRM or on a separate site. The Facebook path uses a configured page and lead form, then reads submissions around the source's saved sync time so a short overlap does not lose new leads. The telephony path uses provider callbacks and call requests to keep call activity in CRM.

ERPNext synchronization

ERPNext synchronization connects CRM sales data with ERPNext business data. The integration can create customer records from CRM deals and can keep CRM products linked to ERPNext items so later quotation and order work uses the same business identity.

The integration is enabled through crm/…/erpnext_crm_settings.py. The settings define whether ERPNext is local or remote, identify the ERPNext company, and control optional product synchronization. When the integration becomes active, CRM prepares the fields and sales actions needed to relate records on both sides.

Product synchronization treats the CRM Product and ERPNext Item as linked views of one catalogue entry. ERPNext item details can update the CRM product. When an item price exists in ERPNext's default selling price list, that price takes precedence over the item's standard rate; the standard rate remains the fallback. Rename and delete actions preserve or remove the linked record as a unit when the link is valid.

Sharing and user access follow the product link as well. User permissions and document shares for a CRM Product are mirrored for its ERPNext Item, and the reverse path is supported when the pair is linked.

For the detailed ERPNext configuration and synchronization rules, see ERPNext synchronization.

References: crm/…/erpnext_crm_settings.py• L24-92 crm/…/erpnext_crm_settings.py• L348-464 crm/…/erpnext_crm_settings.py• L510-634 crm/…/utils.py• L9-23 crm/…/item.py• L13-45 crm/…/item.py• L48-102 crm/…/user_permission.py• L55-87 crm/…/doc_share.py• L51-82 crm/…/test_utils.py• L7-28 crm/…/test_utils.py• L44-128

Facebook lead ingestion

Facebook lead ingestion turns Facebook Lead Ads submissions into CRM Leads. A Lead Sync Source represents one enabled Facebook form and stores the access details, selected page and form, sync frequency, and last sync time.

The source setup discovers the available Facebook pages and lead forms. Each form stores its questions and the CRM field assigned to each question. The form must map the CRM lead's first name before it can be used for normal updates, which protects the minimum data needed for a new lead.

When a source syncs, CRM requests submissions from Facebook from a short overlap before the saved sync time. It maps the configured answers, marks the lead source as Facebook, and stores the Facebook lead and form IDs on the CRM Lead. A submission that already exists for the same form is recorded as a duplicate instead of creating a second lead. Other errors create a failed sync log so the source can continue to process later submissions.

Users can start a sync from the source record. Enabled sources can also run on a five-minute, ten-minute, fifteen-minute, hourly, daily, or monthly schedule. Only one enabled source can use a given Facebook lead form, which prevents competing sources from importing the same campaign.

For the detailed lead-source setup and sync rules, see Lead-source synchronization.

This diagram shows the setup and recurring sync path from a Facebook account to the CRM sales pipeline.

flowchart TD
    Token[Facebook access token] --> Discovery[Page and form discovery]
    Discovery --> Mapping[Question-to-CRM field mapping]
    Mapping --> Source[Enabled Lead Sync Source]
    Source --> Schedule[Manual or scheduled sync]
    Schedule --> API[Facebook lead submissions]
    API --> Dedup[Mapping and duplicate check]
    Dedup -->|new submission| Lead[CRM Lead]
    Dedup -->|duplicate or error| Log[Failed Lead Sync Log]
    Lead --> Pipeline[CRM sales pipeline]

References: crm/…/lead_sync_source.py• L13-69 crm/…/facebook.py• L20-139 crm/…/facebook.py• L142-226 crm/…/facebook_lead_form.py• L28-48 crm/…/background_sync.py• L4-37 crm/hooks.py• L224-241

Telephony integrations

Telephony integrations connect CRM calling with external voice providers. They support incoming call routing, outbound calls, status changes, and recording links while keeping a CRM Call Log tied to a known contact, lead, or deal. The provider-specific flows are implemented for Exotel in crm/…/handler.py and for Twilio through the public handlers in crm/…/api.py and crm/…/twilio_handler.py.

CRM exposes which providers are enabled and the signed-in user's default calling medium. It also matches phone numbers to readable CRM contacts, open leads, and deals so a call can open or link to the right sales record. A call log can carry related notes and tasks, which keeps follow-up work with the call.

CRM serves provider recordings through the call log after checking the saved call record and provider access. It accepts browser range requests for playback and validates each provider URL and redirect before fetching it. Provider credentials apply only to the matching provider URL, and the recording stream does not expose those credentials to the browser.

Exotel accepts secured call events and can start outbound calls for a CRM user. CRM normalizes Exotel status values for the CRM Call Log, treats empty statuses for call legs that did not connect as having no status, and logs unknown values instead of saving an invalid state. It also updates call timing, duration, recording, and agent data as later events arrive. Twilio validates provider callbacks and can route an incoming call to an agent's phone or to an active browser session. When several agents can receive a call, CRM can prefer the owner of the matching deal or open lead. Both providers return call events so CRM can keep the call status and recording data current.

For provider setup and call behavior, see Telephony integrations.

This diagram shows the shared telephony flow from a CRM action or external call to an updated CRM call record.

flowchart LR
    User[CRM user] -->|outbound call| Provider[Exotel or Twilio]
    Caller[External caller] -->|incoming call| Provider
    Provider -->|route to phone or browser| Agent[CRM agent]
    Provider -->|status and recording events| Log[CRM Call Log]
    Log -->|phone match| Record[Lead, deal, or contact]

References: crm/…/api.py• L15-44 crm/…/api.py• L47-83 crm/…/api.py• L86-148 crm/…/api.py• L151-253 crm/…/api.py• L299-432 crm/…/handler.py• L19-75 crm/…/handler.py• L78-147 crm/…/handler.py• L182-243 crm/…/handler.py• L245-342 crm/…/api.py• L13-123 crm/…/api.py• L126-222 crm/…/twilio_handler.py• L12-113 crm/…/twilio_handler.py• L127-213 crm/…/twilio_handler.py• L215-267

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to ERPNext product or customer links must preserve the same-site and remote-site contracts. The CRM fields and any remote custom fields must still identify the same record pair.
  • Changes to product pricing fields or the ERPNext selling price list must preserve the price choice and fallback used to populate CRM Products.
  • Changes to product rename or delete behavior must preserve link cleanup and avoid creating a second record on the other side.
  • Changes to Facebook lead form questions or CRM Lead required fields must keep the question mapping and duplicate check aligned with the data sent by Facebook.
  • Changes to lead sync frequency names must stay aligned between Lead Sync Source values and the scheduled jobs that select them.
  • Changes to the Facebook Graph API response or API version must preserve page discovery, form discovery, lead field extraction, and the saved sync cursor. The overlap window must still work with duplicate detection.
  • Changes to telephony provider callbacks or status names must preserve the mapping to CRM Call Log direction, status, duration, and recording data. For Exotel, keep empty leg statuses distinct from unknown provider statuses.
  • Changes to telephony agent ownership or receiving-device rules must preserve routing to the correct phone or active browser session.
  • Changes to public callback URLs or webhook verification must keep provider events reachable and authenticated.
  • Changes to call recording URLs or playback proxy behavior must preserve call-log permissions, provider authentication, range support, and rejection of unsafe destinations.

Important failure modes

TriggerConsequenceGuard
ERPNext is enabled for the same site but is not installedSettings validation blocks activation or later ERPNext work cannot runValidate the installed app before enabling same-site synchronization
Remote ERPNext URL or API credentials are invalidCustom fields, customer creation, prospect creation, or record links failCheck the remote site settings and review the logged integration error
ERPNext has no default selling price listCRM product prices use the Item standard rate instead of an Item PriceConfigure the intended default selling price list when Item Prices must drive CRM prices
A CRM Product and ERPNext Item have no valid linkCatalogue updates, access mirrors, or quotation item mapping cannot reach the other recordResolve the product-item link and review the open product sync issues
A Facebook access token is invalidPage and form discovery or lead fetch failsReplace the token and run the source again
A Facebook form has no mapped first nameForm validation prevents the mapping from being accepted for useMap the form question to first_name
Two enabled sources use the same Facebook formThe second source cannot be saved as activeKeep one enabled source for each form
A Facebook submission matches an existing lead for its formCRM does not create a second lead and records a duplicate logReview the existing lead or the failed sync log
An Exotel webhook has an invalid verification tokenCRM rejects the call event and does not update the call recordKeep the shared webhook token aligned with Exotel
Exotel sends an unknown call statusCRM leaves the status unchanged and records an error for reviewKeep the provider status map current and inspect unknown-status errors
No eligible Twilio agent has a phone number or active browser sessionThe incoming caller hears that no agent is availableConfigure an agent's receiving device and required contact or session data
A provider sends a recording or callback field that CRM cannot mapThe CRM Call Log can remain incomplete or show stale call dataPreserve provider callback fields and their CRM field mapping
A call recording URL uses an invalid, private, or non-provider destinationCRM refuses to fetch the recordingStore a valid HTTPS provider URL, and allow each redirect to resolve to a public address
A recording provider redirects too many timesCRM stops the fetch instead of following an unbounded chainKeep provider redirects within the allowed hop limit

Key files

FileWhy to read it
crm/…/erpnext_crm_settings.pyDefines the ERPNext integration boundary, site modes, customer and quotation links, and product sync status.
crm/…/item.pyShows how linked ERPNext Items and CRM Products share catalogue data, price selection, and lifecycle changes.
crm/…/utils.pyDefines when synchronization is active and how the two product records find each other.
crm/…/user_permission.py and crm/…/doc_share.pyExplain how access and sharing follow a linked product-item pair.
crm/…/test_utils.pyStates the expected ERPNext hook wiring and catalogue price fallback behavior.
crm/…/lead_sync_source.pyDefines the Facebook source lifecycle, manual sync entry point, and one-source-per-form rule.
crm/…/facebook.pyDefines Facebook discovery, lead mapping, duplicate handling, failure logging, overlap protection, and sync progress.
crm/…/facebook_lead_form.pyDefines the minimum field mapping required before a Facebook form can supply CRM leads.
crm/…/background_sync.py and crm/hooks.pyShow how enabled sources are selected by frequency and run as background jobs.
crm/…/api.pyCovers telephony availability, user calling preferences, phone-based CRM record matching, call follow-up links, and secure call-recording playback.
crm/…/handler.pyCovers Exotel callback verification, outbound call setup, status normalization, and links from call logs to CRM records.
crm/…/api.py and crm/…/twilio_handler.pyCover Twilio webhook validation, call routing, callback events, and call details.