Skip to main content

Import B2B orders

Note

This tutorial describes how to import historical order data. To create and collect payment for B2B orders, refer to the Manage draft orders tutorial instead.

A business-to-business (B2B) merchant might run certain B2B operations outside of Shopify, but want to import their non-Shopify B2B orders into Shopify. This can help the B2B merchant to move their B2B business to Shopify without losing historical order data, and enable buyers to review their full order history within their customer account pages on a Shopify storefront.

In this tutorial, you'll learn how to import orders with the GraphQL Admin API and associate them with B2B company locations and company contacts.



  • A B2B merchant must import or create all relevant companies, company locations, company contacts, and products in Shopify before they can import B2B orders. If these resources aren't created in Shopify before the order import, then an error is returned.

The B2B order import feature uses the GraphQL Admin API's orderCreate mutation to enable B2B merchants to import B2B orders into Shopify.

When you include both companyLocationId and customer.toAssociate in the input, a B2B order is created and associated with the company location.

Caution

The customer must have a role assignment to the specified company location. If the customer doesn't have a role assignment to that location, then an error is returned.

priceSet isn't a required parameter for importing B2B orders. When a merchant doesn't add prices to their line items, the API populates the price automatically based on the variant price.

Because this can result in inaccurate order data, you should implement validation logic within the app to ensure that merchants input accurate price data when importing B2B orders.

When an order is successfully created in a B2B context, the API response includes the following company details via purchasingEntity:

purchasingEntity {
... on PurchasingCompany {
company { id }
location { id }
}
}

The following request creates a B2B order for a company:

Import B2B orders

Mutation

mutation orderCreate($order: OrderCreateOrderInput!) {
orderCreate(order: $order) {
order {
id
name
purchasingEntity {
... on PurchasingCompany {
company { id }
location { id }
}
}
}
userErrors { field message }
}
}

Variables

{
"order": {
"lineItems": [
{
"variantId": "gid://shopify/ProductVariant/123",
"quantity": 1,
"priceSet": {
"shopMoney": {
"amount": "10.20",
"currencyCode": "USD"
}
}
}
],
"customer": {
"toAssociate": {
"id": "gid://shopify/Customer/12345"
}
},
"companyLocationId": "gid://shopify/CompanyLocation/123456789"
}
}

JSON response

{
"data": {
"orderCreate": {
"order": {
"id": "gid://shopify/Order/987",
"name": "#1001",
"purchasingEntity": {
"company": {
"id": "gid://shopify/Company/222"
},
"location": {
"id": "gid://shopify/CompanyLocation/123456789"
}
}
},
"userErrors": []
}
}
}

Was this page helpful?