Good shout @Luke! There is a GraphQL option - it’s just not in the docs in the form of a tutorial like REST is.
The orderCreate mutation supports a companyLocationId field in its input that works the same way as the REST endpoint - I just tested it in my dev store and confirmed it works.
Here’s the GraphQL approach:
mutation orderCreate($order: OrderCreateOrderInput!) {
orderCreate(order: $order) {
order {
id
purchasingEntity {
... on PurchasingCompany {
company { id name }
location { id name }
}
}
}
userErrors {
field
message
}
}
}
Variables:
{
"order": {
"lineItems": [{
"title": "Product Name",
"quantity": 1,
"priceSet": {
"shopMoney": {
"amount": "10.00",
"currencyCode": "CAD"
}
}
}],
"customer": {
"toAssociate": {
"id": "gid://shopify/Customer/12345"
}
},
"companyLocationId": "gid://shopify/CompanyLocation/67890"
}
}
Same requirement as REST: the customer needs a role assignment to that company location or you’ll get an error.
The limitation still stands though - this only works when creating new orders, not for migrating existing ones. The CompanyLocationMigrateOrders mutation Mark found is internal-only and there’s no public API equivalent for retroactively linking orders to companies.
So for 100K already-imported orders, the options are still either the admin UI’s migration tool or deleting and re-importing with company data from the start. The GraphQL method just gives an alternative to REST for the import approach. (I’ll submit feedback to get the docs updated to use GraphQL for the B2B order import tutorial, thanks again!)