Skip to content

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/orders and POST /admin/orders/export return personal orders only. Company orders are under /admin/b2b/orders.
  • GET /admin/orders/:id and GET /admin/draft-orders/:id return HTTP 404 for a company order or draft order.
  • GET /admin/draft-orders also excludes company draft orders. Read them through /admin/b2b/draft-orders.
  • GET /admin/reservations leaves out reservations for company orders; they are under /admin/b2b/reservations.
  • GET /store/orders returns personal orders only.
  • GET /store/orders/:id refuses a company order with HTTP 403. Read it through /store/b2b/companies/:company_id/orders/:order_id.

Authentication and access

RoutesAuthenticationAccess
/store/b2bA 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/b2bA 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 pathWhat it does
GET /store/b2b/me/companiesList the signed-in customer’s active companies.
POST /store/b2b/me/companiesCreate a company with the signed-in customer as its only buyer.
GET /store/b2b/companies/:company_idRead the company visible to the signed-in buyer.
GET /store/b2b/companies/:company_id/productsList products with company pricing.
GET /store/b2b/companies/:company_id/products/:idRead a product with company pricing.
GET /store/b2b/companies/:company_id/product-variantsList variants with company pricing.
GET /store/b2b/companies/:company_id/product-variants/:idRead 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.

FieldUsage
nameRequired. Company name, 1–200 characters.
currency_codeRequired. Three lowercase letters, such as eur.
billing_addressRequired. 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 pathWhat it does
GET · POST /store/b2b/companies/:company_id/addressesList 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_idRead 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 pathWhat it does
GET · POST /store/b2b/companies/:company_id/cartsList 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_idRead 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-itemsAdd 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_idUpdate {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/promotionsApply, 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-optionsList the cart’s available shipping options. Returns {shipping_options}.
POST /store/b2b/companies/:company_id/carts/:cart_id/shipping-options/:option_id/calculateCalculate this shipping option’s price with {data?,cart_id?}. Returns {shipping_option}.
POST /store/b2b/companies/:company_id/carts/:cart_id/shipping-methodsSelect a shipping method with {option_id}. Returns {cart}.
POST /store/b2b/companies/:company_id/carts/:cart_id/taxesRecalculate taxes using Medusa. Returns {cart}.
POST /store/b2b/companies/:company_id/carts/:cart_id/customerSet 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-collectionsCreate 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-sessionsStart 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_idUpdate a payment session of this cart with {client_data}. Returns {cart,payment_collection}.
POST /store/b2b/companies/:company_id/carts/:cart_id/completePlace the company order. The cart must have email and shipping_address.phone. Send {}. Returns {order}.

Create a company cart

FieldUsage
region_idRequired. Region using the company’s currency.
sales_channel_idRequired. A channel covered by the publishable key.
address_idOptional. A company address to use for shipping.
emailOptional at creation. Set it explicitly; it is not copied from the customer. Required before payment and checkout.
shipping_addressOptional. 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 pathWhat it does
GET /store/b2b/companies/:company_id/orders · GET /store/b2b/companies/:company_id/orders/:order_idList the company’s orders or read one. Each includes company and b2b_context.
POST /store/b2b/companies/:company_id/returnsCreate 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/requestRequest a transfer with {description?,update_order_email?}. Returns {order}.
POST /store/b2b/companies/:company_id/orders/:order_id/transfer/acceptAccept a transfer with {token}. Returns {order}.
POST /store/b2b/companies/:company_id/orders/:order_id/transfer/declineDecline a transfer with {token}. Returns {order}.
POST /store/b2b/companies/:company_id/orders/:order_id/transfer/cancelCancel 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

VariableWhere to find it
MEDUSA_BACKEND_URLYour Medusa backend URL.
MEDUSA_CUSTOMER_TOKENToken from native customer authentication.
MEDUSA_PUBLISHABLE_KEYA publishable key covering the sales channel.
COMPANY_IDAn 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_IDAn existing region matching the company currency and a sales channel.
VARIANT_ID, PAYMENT_PROVIDER_IDAn 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
// 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

Terminal
node company-cart.mjs

The script prints the company, cart and order IDs.

Admin routes

Companies and buyers

Method and pathWhat it does
GET · POST /admin/b2b/companiesList or create companies, with an optional billing address.
GET · POST /admin/b2b/companies/:company_idRead or update a company.
GET /admin/b2b/buyers · GET /admin/b2b/buyers/:idList 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_idAdd 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/createCreate 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/addressesList 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 pathWhat it does
GET · POST /admin/b2b/company-groupsList or create company groups. Manage their members at /admin/b2b/company-groups/:group_id/companies.
GET · POST /admin/b2b/price-lists/:id/audienceRead or replace a price list’s audience.
GET · POST /admin/b2b/promotions/:id/audienceRead or replace a promotion’s audience.
POST /admin/b2b/price-listsCreate a price list with the targeting fields below.
POST /admin/b2b/promotionsCreate a promotion with the targeting fields below.
GET · POST /admin/b2b/campaignsList or create campaigns in the B2B purchase context, with native budgets and dates. Targeting remains on their promotions.
GET · POST · DELETE /admin/b2b/campaigns/:idRead, update or delete a B2B campaign using the native Campaign contract.
POST /admin/b2b/campaigns/:id/promotionsAssociate 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 pathWhat it does
GET · POST /admin/b2b/ordersList company orders or create one for a company.
GET · POST /admin/b2b/draft-ordersList or create company draft orders using Medusa’s draft-order flow.
GET /admin/b2b/carts · GET /admin/b2b/carts/:idList company carts or read one with its company and purchase_state object. List: {carts,count,offset,limit}. Detail: {cart}.
POST /admin/b2b/carts/:id/draftCreate 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-preparationsRead 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 pathWhat it does
GET · POST /admin/b2b/settings/commerceRead or change the commerce mode. POST accepts {mode:"mixed"|"b2b_only"}.
GET /admin/b2b/searchNative 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):

json
{
  "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 /audience routes, [] removes that list’s restriction and may widen the audience.
  • The /audience routes also accept commerce_types: b2b, b2c or both. Omitting it keeps the existing commerce rule.
json
{
  "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.

FieldUsage
modeRequired. 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_keyRequired. A non-empty key, up to 120 characters. Reuse it to retry the same request.
customer_idOptional. 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 stateMeaning
preparedThe cart snapshot has been saved.
creatingThe native draft order is being created.
readyThe draft order and its company links are complete.
needs_recoveryPreparation 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:

ListDefault limit
Core lists, unless specified otherwise20
Admin Companies and Company addresses; Company buyers (…/companies/:company_id/buyers)100
Admin orders15
Catalogue and draft ordersMedusa’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 statusMeaning
400Invalid data
401Customer or Admin user not signed in
403Access refused (Company membership or Admin permission), or a company order read through a personal route
404Resource not found, or outside this Company or route segment
409Operation conflicts with the cart or preparation state, or reuses an idempotency key with different fields.
422duplicate_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.

StateMeaning
openNo module blocks buyer changes. Other cart and access checks still apply.
heldHeld by a purchase hold from another module or an interrupted Core cart-to-draft transfer. Buyer changes are refused; authorised reads remain available.
transferredTransferred 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.