The B2B storefront experience starts with the ability to register and log in with a company account. In this section, we’ll look at the core GraphQL workflow supporting company creation, as well as the other component needed for a minimal buying experience: a company address book.
Creating a B2B company requires an existing customer account to serve as the company’s admin user. This means the first step in the registration workflow is to create the customer account if it doesn’t exist already, using the customerCreate mutation. The customerEmail as well as customerId will be required to use the companyCreate mutation.
originChannelId and channelIds as an array. channelIds specifies the channels in which the customer can operate, which might include multiple channels if your store configuration allows this.authentication field can be used to set the new customer’s password (newPassword). This should be paired with setting forcePasswordReset to FALSE to ensure the customer is not forced to reset their password on their first login.Once a BigCommerce customer account exists, you can proceed with the registration of a company.
The companyCreate mutation is an anonymous operation; no existing authentication token is required for the request; however customerEmail as well as customerId are now required.
companyEmail field does not need to match the email address of the customer corresponding with customerId. This will be the email associated directly with the company record, not with an individual user.The “Default customer group” configured in your B2B Edition settings, if any, will determine the customer group that is assigned to a company registered via GraphQL. The customer group set on the existing Admin customer will automatically be updated to reflect this.
If your B2B Edition has not been upgraded with the Independent Company feature, a new customer group specific to the company will instead be created.
As we’ve seen, the login mutation is used with a store hash and an existing customer’s email and password. This mutation is key for performing many other queries and mutations, as it is used to retrieve a value used as the Bearer authentication token in subsequent requests.
id) and the BigCommerce customer ID (bcId) can be queried on the user object in the response.token from the response, for authenticating further requests, but also user.id, since the user’s ID is required as an argument for a number of queries as well. The BigCommerce customer ID, which is available in user.bcId, might also be required for some queries.login mutation will succeed even for a customer that is not associated with a company, but the user object will be empty.An easy way to verify that the token you’ve received from login is still valid, verify you are using the token correctly, and inspect the details of the user’s associated company, is to use the userCompany query, passing the corresponding user ID in addition to including the appropriate Authorization header.
id in this context is the ID of the company. Like the user ID, this is often an important value to retain for use in the arguments of other queries.
The possible values of companyStatus are:
As seen above, you must provide an initial address when creating a company. This will become the first address in the company’s address book, allowed for both shipping and billing.
Add new addresses with the addressCreate mutation.
addressCreate is available only when the user associated with the Bearer token has the Admin role or a custom role with the “Addresses - Create, edit, delete” permission.
companyId is a required argument.isShipping and isBilling fields to indicate this.isDefaultShipping and isDefaultBilling fields to indicate the new address should be the default Shipping or Billing address, respectively. Any newly created address with one or both of these set will override an address that was previously set as default.company field is optional and is only for the context of the address. (It may or may not match the name of the B2B company.)Fetch the details of the addresses belonging to the user’s company with the addresses query or (if you know the ID of a specific address) the address query.
addresses and address are available for any built-in user role or for custom roles with the “Addresses - View” permission.
addresses supports the typical pagination arguments (offset, before, after, first, last)addresses can also be filtered w_addresses_ith arguments matching the exact values of most address fields (for example, firstName, country, or label).The address query returns the same GraphQL type as each node returned from addresses, so all the same fields can be queried.
Updating and deleting company addresses is straightforward, using the addressUpdate and addressDelete mutations.
addressUpdate and addressDelete are available only when the user associated with the Bearer token has the Admin role or a custom role with the “Addresses - Create, edit, delete” permission.