Core API
Use the Store API for company purchasing in your storefront and the Admin API for merchant operations. Both use Medusa authentication.
Personal and company routes
Installing Core changes the native routes below: they return only personal resources, and refuse access to individual company orders. Use the corresponding B2B routes for company purchases.
GET /admin/ordersandPOST /admin/orders/exportreturn personal orders only. Company orders are under/admin/b2b/orders.GET /admin/orders/:idandGET /admin/draft-orders/:idreturn HTTP 404 for a company order or draft order.GET /admin/draft-ordersalso excludes company draft orders. Read them through/admin/b2b/draft-orders.GET /admin/reservationsleaves out reservations for company orders; they are under/admin/b2b/reservations.GET /store/ordersreturns personal orders only.GET /store/orders/:idrefuses a company order with HTTP 403. Read it through/store/b2b/companies/:company_id/orders/:order_id.
Authentication and access
| Routes | Authentication | Access |
|---|---|---|
/store/b2b | A publishable API key (x-publishable-api-key) and a signed-in customer (session or bearer token). | The server identifies the customer from authentication. Routes under /store/b2b/companies/:company_id also require an active company and an active buyer membership. |
/admin/b2b | A signed-in Admin user (session or bearer token). Medusa secret API keys are not accepted. | Medusa’s backend permission checks apply to each operation. |
Keep Admin credentials on your backend; never send them to the storefront.
Store routes
Replace :company_id with the ID of the company chosen by the signed-in customer. List their companies with GET /store/b2b/me/companies.
Companies and catalogue
| Method and path | What it does |
|---|---|
GET /store/b2b/me/companies | List the signed-in customer’s active companies. |
POST /store/b2b/me/companies | Create a company with the signed-in customer as its only buyer. |
GET /store/b2b/companies/:company_id | Read the company visible to the signed-in buyer. |
GET /store/b2b/companies/:company_id/products | List products with company pricing. |
GET /store/b2b/companies/:company_id/products/:id | Read a product with company pricing. |
GET /store/b2b/companies/:company_id/product-variants | List variants with company pricing. |
GET /store/b2b/companies/:company_id/product-variants/:id | Read a variant with company pricing. |
For product and variant routes, region_id is required; its currency must match the company’s. Set sales_channel_id when the publishable key covers several channels. A supplied cart_id must belong to this company and use the same region and channel.
Create a company from the storefront
Send POST /store/b2b/me/companies with the fields below. The response is HTTP 201 {company}. The request body cannot set a customer ID, status, group or metadata.
| Field | Usage |
|---|---|
name | Required. Company name, 1–200 characters. |
currency_code | Required. Three lowercase letters, such as eur. |
billing_address | Required. An object containing at least address_1, city, postal_code and country_code (two lowercase letters). |
Optional billing-address fields and their limits are listed in the Core HTTP reference.
Addresses
| Method and path | What it does |
|---|---|
GET · POST /store/b2b/companies/:company_id/addresses | List or add shared addresses. POST accepts the native address fields with optional kind and label; see the Core HTTP reference for the complete address format. |
GET · POST · DELETE /store/b2b/companies/:company_id/addresses/:address_id | Read or update an address. Only shipping addresses can be deleted (soft delete). Read response: {address}. Delete response: {id,object:"address",deleted:true,parent:company}. |
Carts and checkout
When a request body includes cart_id, it must match the cart ID in the URL.
| Method and path | What it does |
|---|---|
GET · POST /store/b2b/companies/:company_id/carts | List company carts ({carts,count,limit,offset}), or create one with the fields below (HTTP 201 {cart}). |
GET · POST /store/b2b/companies/:company_id/carts/:cart_id | Read or update the cart with address_id, email or shipping_address. Returns {cart}, including cart.b2b_purchase_state. |
POST /store/b2b/companies/:company_id/carts/:cart_id/line-items | Add an item with {variant_id,quantity}. Quantity is an integer from 1 to 10,000. Returns {cart}. |
POST · DELETE /store/b2b/companies/:company_id/carts/:cart_id/line-items/:line_id | Update {quantity} or remove an item. Quantity is an integer from 1 to 10,000. Returns {cart}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/promotions | Apply, remove or replace codes with {promo_codes,action?}. action is add (default), remove or replace. Returns {cart} with Medusa’s promotion result. |
GET /store/b2b/companies/:company_id/carts/:cart_id/shipping-options | List the cart’s available shipping options. Returns {shipping_options}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/shipping-options/:option_id/calculate | Calculate this shipping option’s price with {data?,cart_id?}. Returns {shipping_option}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/shipping-methods | Select a shipping method with {option_id}. Returns {cart}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/taxes | Recalculate taxes using Medusa. Returns {cart}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/customer | Set cart.customer_id to the signed-in customer. The original creator and existing email do not change. Returns {cart}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/payment-collections | Create the cart’s payment collection, or return the existing one, with {cart_id?}. Returns {payment_collection,cart}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/payment-sessions | Start a payment session with {provider_id,data?}. The cart must have email and shipping_address.phone. Returns {cart,payment_collection}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/payment-sessions/:session_id | Update a payment session of this cart with {client_data}. Returns {cart,payment_collection}. |
POST /store/b2b/companies/:company_id/carts/:cart_id/complete | Place the company order. The cart must have email and shipping_address.phone. Send {}. Returns {order}. |
Create a company cart
| Field | Usage |
|---|---|
region_id | Required. Region using the company’s currency. |
sales_channel_id | Required. A channel covered by the publishable key. |
address_id | Optional. A company address to use for shipping. |
email | Optional at creation. Set it explicitly; it is not copied from the customer. Required before payment and checkout. |
shipping_address | Optional. Cart-specific address fields that supplement or replace the copied address. These changes do not update the company address book. |
address_id and shipping_address can be used together. Without address_id, Core copies the default shipping address; if there is none, the first shipping address; otherwise the billing address.
Orders, returns and order transfers
| Method and path | What it does |
|---|---|
GET /store/b2b/companies/:company_id/orders · GET /store/b2b/companies/:company_id/orders/:order_id | List the company’s orders or read one. Each includes company and b2b_context. |
POST /store/b2b/companies/:company_id/returns | Create a Medusa return for a company order. Use the native body with order_id, items and return_shipping; see the native HTTP contracts. Returns {return}. |
POST /store/b2b/companies/:company_id/orders/:order_id/transfer/request | Request a transfer with {description?,update_order_email?}. Returns {order}. |
POST /store/b2b/companies/:company_id/orders/:order_id/transfer/accept | Accept a transfer with {token}. Returns {order}. |
POST /store/b2b/companies/:company_id/orders/:order_id/transfer/decline | Decline a transfer with {token}. Returns {order}. |
POST /store/b2b/companies/:company_id/orders/:order_id/transfer/cancel | Cancel a transfer with {}. Returns {order}. |
These routes use Medusa’s native order transfer. The signed-in buyer requests the order’s transfer to themselves and must be an active buyer of its company. Their buyer membership must still be active when the transfer is accepted. The order stays linked to the same company. This is separate from the cart transfer mode used to create draft orders.
Example: company cart and checkout
Run this example with the Node.js version used by your Medusa application. It places an order on a test backend with a configured payment provider. A provider requiring customer confirmation needs its own frontend flow before checkout.
Buyer contact details
Use the signed-in buyer’s email for cart.email and provide shipping_address.phone. These cart fields are required to start payment and place the order. The example below retrieves the buyer’s email with Medusa’s GET /store/customers/me route.
Prepare the inputs
| Variable | Where to find it |
|---|---|
MEDUSA_BACKEND_URL | Your Medusa backend URL. |
MEDUSA_CUSTOMER_TOKEN | Token from native customer authentication. |
MEDUSA_PUBLISHABLE_KEY | A publishable key covering the sales channel. |
COMPANY_ID | An active company the customer belongs to, with a complete billing address. Core resolves a shipping address using the fallback order described above. |
REGION_ID, SALES_CHANNEL_ID | An existing region matching the company currency and a sales channel. |
VARIANT_ID, PAYMENT_PROVIDER_ID | An in-stock variant priced in this currency and channel, and a configured test payment provider. |
Save the script
Save the code below as company-cart.mjs. Export the variables above in your terminal.
// company-cart.mjs — node company-cart.mjs against a test backend.
const names = ["MEDUSA_BACKEND_URL", "MEDUSA_CUSTOMER_TOKEN", "MEDUSA_PUBLISHABLE_KEY",
"COMPANY_ID", "REGION_ID", "SALES_CHANNEL_ID", "VARIANT_ID", "PAYMENT_PROVIDER_ID"]
for (const name of names) {
if (!process.env[name]) throw new Error(`Missing environment variable: ${name}`)
}
const env = process.env
async function store(path, data) {
const response = await fetch(`${env.MEDUSA_BACKEND_URL}${path}`, {
method: data === undefined ? "GET" : "POST",
headers: {
"Content-Type": "application/json",
"x-publishable-api-key": env.MEDUSA_PUBLISHABLE_KEY,
Authorization: `Bearer ${env.MEDUSA_CUSTOMER_TOKEN}`,
},
...(data === undefined ? {} : { body: JSON.stringify(data) }),
})
const payload = await response.json()
if (!response.ok) throw new Error(JSON.stringify(payload))
return payload
}
const C = `/store/b2b/companies/${encodeURIComponent(env.COMPANY_ID)}`
await store(C) // checks this signed-in customer’s active membership
await store(`${C}/products?region_id=${encodeURIComponent(env.REGION_ID)}&sales_channel_id=${encodeURIComponent(env.SALES_CHANNEL_ID)}&limit=20&offset=0`)
const { customer } = await store("/store/customers/me")
const { cart } = await store(`${C}/carts`, {
region_id: env.REGION_ID, sales_channel_id: env.SALES_CHANNEL_ID,
email: customer.email, shipping_address: {
first_name: "Alice", last_name: "Example", address_1: "10 Example Street",
city: "Lyon", postal_code: "69001", country_code: "fr", phone: "+33000000000",
},
})
const P = `${C}/carts/${cart.id}`
await store(`${P}/line-items`, { variant_id: env.VARIANT_ID, quantity: 1 })
const { shipping_options } = await store(`${P}/shipping-options`)
if (!shipping_options.length) throw new Error("Prepare an eligible test shipping option")
await store(`${P}/shipping-methods`, { option_id: shipping_options[0].id })
await store(`${P}/payment-sessions`, { provider_id: env.PAYMENT_PROVIDER_ID })
const { order } = await store(`${P}/complete`, {})
console.log({ company_id: env.COMPANY_ID, cart_id: cart.id, order_id: order.id })Run the example
node company-cart.mjsThe script prints the company, cart and order IDs.
Admin routes
Companies and buyers
| Method and path | What it does |
|---|---|
GET · POST /admin/b2b/companies | List or create companies, with an optional billing address. |
GET · POST /admin/b2b/companies/:company_id | Read or update a company. |
GET /admin/b2b/buyers · GET /admin/b2b/buyers/:id | List buyers or read their native customer details. :id is the Medusa customer ID. |
POST /admin/b2b/companies/:company_id/buyers · DELETE /admin/b2b/companies/:company_id/buyers/:customer_id | Add or reactivate with {customer_id}, or revoke the membership. validateBuyerGrant can refuse activation. Repeating the same membership request does not create another membership. |
POST /admin/b2b/companies/:company_id/buyers/create | Create a native guest Customer and Company membership with {email,first_name?,last_name?,phone?}. No store authentication identity or invitation is created. An existing email returns HTTP 422 duplicate_error; add that Customer with POST /admin/b2b/companies/:company_id/buyers instead. Company update and Customer create permissions are required. |
GET · POST /admin/b2b/companies/:company_id/addresses | List or add addresses in the company’s shared address book. |
Later Store registration creates a separate Customer and does not claim the guest contact’s Company membership. Add the registered Customer explicitly to authorise its Company access. Revoking the obsolete guest membership preserves its historical Customer.
Groups, prices and promotions
| Method and path | What it does |
|---|---|
GET · POST /admin/b2b/company-groups | List or create company groups. Manage their members at /admin/b2b/company-groups/:group_id/companies. |
GET · POST /admin/b2b/price-lists/:id/audience | Read or replace a price list’s audience. |
GET · POST /admin/b2b/promotions/:id/audience | Read or replace a promotion’s audience. |
POST /admin/b2b/price-lists | Create a price list with the targeting fields below. |
POST /admin/b2b/promotions | Create a promotion with the targeting fields below. |
GET · POST /admin/b2b/campaigns | List or create campaigns in the B2B purchase context, with native budgets and dates. Targeting remains on their promotions. |
GET · POST · DELETE /admin/b2b/campaigns/:id | Read, update or delete a B2B campaign using the native Campaign contract. |
POST /admin/b2b/campaigns/:id/promotions | Associate with {add?:string[],remove?:string[]}. Add unattached business-only promotions; shared B2C/B2B promotions cannot join a B2B campaign. Remove only promotions already owned by this campaign. |
Orders and carts
| Method and path | What it does |
|---|---|
GET · POST /admin/b2b/orders | List company orders or create one for a company. |
GET · POST /admin/b2b/draft-orders | List or create company draft orders using Medusa’s draft-order flow. |
GET /admin/b2b/carts · GET /admin/b2b/carts/:id | List company carts or read one with its company and purchase_state object. List: {carts,count,offset,limit}. Detail: {cart}. |
POST /admin/b2b/carts/:id/draft | Create a draft order from a cart. Fields and retry behaviour are explained below. Returns HTTP 201 {preparation,draft_order_id}. |
GET /admin/b2b/carts/:id/draft-preparations | Read the cart’s preparation history, newest first, with offset and limit. States: prepared, creating, ready, needs_recovery. |
Filter GET /admin/b2b/carts with company_id or q (both optional). Pagination uses limit (1–100, default 20) and offset (0 or higher, default 0).
Settings and search
| Method and path | What it does |
|---|---|
GET · POST /admin/b2b/settings/commerce | Read or change the commerce mode. POST accepts {mode:"mixed"|"b2b_only"}. |
GET /admin/b2b/search | Native global search with the B2B segment for orders, buyers, price lists and promotions. Native entity validation/permissions and response shape are retained. Search Companies from their directory, not a Company entity in global search. |
Target price lists and promotions
POST /admin/b2b/price-lists and POST /admin/b2b/promotions take Medusa’s usual body plus a targeting field (up to 100 IDs per list):
{
"additional_data": {
"b2b_audience": {
"company_ids": ["bcomp_example"],
"company_group_ids": ["bgroup_example"]
}
}
}- Matching any value in a list is enough.
- If companies and company groups are both specified, both conditions must match.
- For example, targeting company A and group G applies to A only when A belongs to G. It does not apply to every company in G.
At creation, additional_data.b2b_audience accepts only company_ids and company_group_ids. To replace an audience later, use the /audience routes with these fields and the optional commerce_types array.
- On the
/audienceroutes,[]removes that list’s restriction and may widen the audience. - The
/audienceroutes also acceptcommerce_types:b2b,b2cor both. Omitting it keeps the existing commerce rule.
{
"company_ids": ["bcomp_example"],
"company_group_ids": ["bgroup_example"],
"commerce_types": ["b2b"]
}Prepare a draft order from a cart
Send POST /admin/b2b/carts/:id/draft with only these fields. Any other field, including company_id or an actor ID, is rejected with HTTP 400. The server determines the company and Admin user.
| Field | Usage |
|---|---|
mode | Required. copy keeps the cart available for purchase. transfer sets it to transferred after creating the draft: buyer changes are blocked, but authorised reads remain available. |
idempotency_key | Required. A non-empty key, up to 120 characters. Reuse it to retry the same request. |
customer_id | Optional. Customer to associate with the draft order; they must be an active buyer of the company. |
The response is HTTP 201 {preparation,draft_order_id}, including a successful retry of the same request. The draft stays private; this operation does not publish a quote or sales proposal.
| Preparation state | Meaning |
|---|---|
prepared | The cart snapshot has been saved. |
creating | The native draft order is being created. |
ready | The draft order and its company links are complete. |
needs_recovery | Preparation is incomplete and requires backend investigation. No automatic repair is provided. |
Use a new key to change the mode or customer; changing them with the same key returns HTTP 409. After an interruption, check GET /admin/b2b/carts/:id/draft-preparations. A preparation in needs_recovery is not repaired by retrying. The Core extensions reference explains the detailed field and retry rules.
These tables cover the main merchant operations. See the complete route inventory for all routes and aliases.
Common formats
Pagination
Core lists use limit (1–100) and offset (0 or higher), except catalogue and draft order routes, which follow Medusa’s own parameters. Defaults are listed below:
| List | Default limit |
|---|---|
| Core lists, unless specified otherwise | 20 |
Admin Companies and Company addresses; Company buyers (…/companies/:company_id/buyers) | 100 |
| Admin orders | 15 |
| Catalogue and draft orders | Medusa’s route-specific parameters |
Responses include the collection, count, limit and offset.
Errors and caching
Errors use Medusa’s {type,message,code?} format. B2B responses use Cache-Control: private, no-store.
| HTTP status | Meaning |
|---|---|
| 400 | Invalid data |
| 401 | Customer or Admin user not signed in |
| 403 | Access refused (Company membership or Admin permission), or a company order read through a personal route |
| 404 | Resource not found, or outside this Company or route segment |
| 409 | Operation conflicts with the cart or preparation state, or reuses an idempotency key with different fields. |
| 422 | duplicate_error: a Buyer creation email already exists. Associate the existing Customer explicitly. |
Cart state
In Store cart responses, cart.b2b_purchase_state is a string: open, held or transferred. In Admin cart responses, the same state is in cart.purchase_state.state.
| State | Meaning |
|---|---|
open | No module blocks buyer changes. Other cart and access checks still apply. |
held | Held by a purchase hold from another module or an interrupted Core cart-to-draft transfer. Buyer changes are refused; authorised reads remain available. |
transferred | Transferred to a draft order. Further buyer changes are refused. Authorised buyers can still read it. |
Changing a held or transferred cart returns HTTP 409 with type:"conflict" and code:"invalid_state_error" in Medusa 2.23.1. Internal labels such as cart_held are not stable HTTP error codes. For cart-to-draft retries, inspect the preparation state.
Retry a request
Creating a Company, cart or direct order again can create a duplicate. If a response is lost, reread the resource before creating another. An authorised Buyer who still has active access to the same Company can complete an already completed cart and retrieve its existing order. A revoked Buyer is refused. Access and native validation still apply; the retry does not create another order. Cart-to-draft requests use idempotency_key, as described above.
Revoke a buyer’s access
Deactivating a buyer’s membership removes their access to the company’s carts and orders from their next request, including resources they created. Their valid customer session does not restore this company access. The company’s purchase history is retained.