The ERPNext Medusa Integration maps Medusa customers to ERPNext Lead and Customer records. New registrations create a Lead; the Lead is converted to a Customer when a purchase order is approved. This page covers how the lifecycle works, how records are linked viaDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/aerele/medusa_integration/llms.txt
Use this file to discover all available pages before exploring further.
medusa_id, and how to manage addresses and manually link existing customers.
Registration flow: Lead creation
When a new customer signs up on the Medusa storefront, thesign_up() endpoint calls Medusa’s own signup API, then enqueues insert_lead() as a background job to create the ERPNext record:
insert_lead() creates an ERPNext Lead with the Medusa customer ID stored in medusa_id:
The medusa_id field
Both the Lead and Customer doctypes have a custommedusa_id field. This is the primary key used to look up ERPNext records from Medusa data.
Lookups throughout the integration follow this pattern:
create_quotation(), the integration first checks for a Customer record with the given medusa_id. If none is found, it falls back to searching Lead records:
Lead to Customer conversion
When an order is approved, the integration can automatically promote a Lead to a Customer. This happens insideupdate_quotation() when create_so=true and the Quotation is currently linked to a Lead:
The converted Customer inherits the Lead’s
medusa_id indirectly: the Lead’s fields are mapped across via get_mapped_doc. If the medusa_id field is not included in the mapping, you should link it manually using link_medusa_lead() (described below).Manually linking a Customer to a Medusa Lead
For cases where an ERPNext Customer already exists and needs to be associated with a Medusa account, thelink_medusa_lead() utility function is available:
public/js/customer.js which adds this button).
Address management
Billing addresses are created or updated during quotation creation. Whencreate_quotation() receives a billing_address payload, it:
- Resolves the country code to an ERPNext Country name.
- If
is_default=true, checks whether the customer already has a primary billing address. If one exists, it is updated in place; otherwise a new Address is created and marked as primary. - If
is_default=false, a new Address is always created. - Links the Address to the Customer via a Dynamic Link.
- Sets
quote.customer_addressto the address name.
update_address() endpoint allows subsequent address updates:
address_line1, address_line2, city, state, country, pincode. The endpoint resolves the customer_id to its linked Address via Dynamic Link.
Fetching unlinked customers
Thefetch_all_customers() endpoint returns all ERPNext Customers that do not yet have a medusa_id. This is used to find existing customers who need to be linked to Medusa accounts.
name as a query parameter to filter results by customer name (supports multi-word searches).
Customer group and sales team
All customers created through the ecommerce flow are assigned:| Field | Value |
|---|---|
customer_group | "Ecommerce Customer" |
sales_team[0].sales_person | "Website Sales" |
sales_team[0].contribution | 100 |