We’ve previously emphasized the relationship between the Buyer Portal and the B2B GraphQL API.
Let’s take a closer look at the Buyer Portal’s core architecture for GraphQL querying and the patterns you can use in your own custom Buyer Portal implementation.
The most significant layers involved with GraphQL querying include:
B3Request): This global object handles the low-level details of HTTP requests, including handling global error behavior. This single entry point handles client-side requests to both the main BigCommerce GraphQL Storefront API and the B2B GraphQL API. We’re mainly concerned with the latter, which are performed with B3Request.graphqlB2B.@/shared/service/b2b): Domain-focused modules (invoices, orders, quotes, shopping lists, etc.) that define GraphQL operations and call B3Request.graphqlB2B. They hide query strings and response shapes from the rest of the app.Pages and components don’t deal directly with the GraphQL endpoint URL, headers, or token handling, relying instead on one or both of the above layers.
There are two main patterns for making requests to the B2B GraphQL API.
For one-off or simple calls, you can use B3Request.graphqlB2B with a query and optional variables. The request layer will:
Authorization: Bearer <B2BToken> header from the store.data part of the response, or handle errors (e.g. 40101 → redirect to login, others → snackbar or throw).Example (query with variables):
You don’t set the URL or the auth header; the request layer does that for you.
For commonly used queries and mutations, call named functions from @/shared/service/b2b (or its submodules). Each function encapsulates one GraphQL operation and uses B3Request.graphqlB2B internally.
Example — Invoices:
Service modules live in shared/service/b2b/graphql/ (e.g. invoice.ts, orders.ts, quote.ts). Each file defines:
B3Request.graphqlB2B({ query, variables }) and return the result.Using these service functions is the easiest way to incorporate GraphQL data into your own components when your use case matches one of the predefined operations.
Recall that the Buyer Portal actually uses both the B2B GraphQL API and the standard BigCommerce GraphQL Storefront API.
If you need to make requests to the GraphQL Storefront API from your Buyer Portal code, the B3Request object handles these as well:
graphqlBC makes requests directly to the /graphql endpoint on your storefront domain.graphqlBCProxy proxies requests through an endpoint on the B2B backend.We’ll discuss the reason for these two methods in a future section, as we explore the authentication flow behind the portal’s API requests. For now, just be aware that graphqlBC is appropriate for Stencil storefronts and graphqlBCProxy is appropriate for headless storefronts. Examine the codebase for examples of how window.B3.setting.platform is inspected to make this distinction.