GraphQL Storefront API: Carts and Checkout
BigCommerce’s GraphQL Storefront API provides the same access to cart and checkout objects as the REST Storefront API. Having access to cart and checkout data in the graph alongside related data makes it easier to build headless storefront applications.
Developers can use frontend GraphQL to create an end-to-end shopper experience. Cart and checkout-related mutations and queries can do the following:
- Create a cart
- Add products to a cart
- View or manage a cart
- Create cart redirect URLs
- Create cart metafields
- Fill out checkout details
- Determine the cost of shipping and select a shipping method
- Complete checkout by converting a cart into an order
- Generate a payment access token
Limitations As of this writing, the GraphQL Storefront API does not support the following features:
- File upload product options
- Buy Online, Pick up in Store
- Checkout directly from the Product Details Page, or Buy Now carts
Tokens
To make requests, create a store-level API account with one or more of the following token creation OAuth scopes:
- Storefront API Tokens
- Storefront API Customer Impersonation Tokens
No additional scopes are required to use the GraphQL Storefront API.
To generate a bearer token to authenticate calls to the GraphQL Storefront API, use either the Create a storefront token or the Create a customer impersonation token REST endpoint. On a Stencil storefront, you can also access a token at render time using a Handlebars property. Learn more about Authenticating requests to the GraphQL Storefront API.
For more information, see Creating a token in Authenticating requests to the GraphQL Storefront API and dynamic tokens in the Authentication and example requests article.
Handling payments
To handle payments, use the Payments API (Overview).
For PCI compliance-related reasons, the GraphQL Storefront API does not handle payments. You can use the Payments API (Reference) to process payments.
The GraphQL Storefront API returns the checkout ID and order ID, which you can use to Get accepted payment methods and Create a payment access token.
The GraphQL Storefront API returns the customer ID, which you can use to Get stored payment instruments. To learn more about authenticating REST endpoints, locate the Authentication section at the top of each endpoint, then click Show Details.
Gift certificates are a type of payment instrument similar to a debit card, so the Payments API must apply the gift certificate to the checkout.
The API account you use to process payments must have the scopes specified in the Payments API Overview.
Example queries and mutations
Create a cart using a simple product
Request
Response
Get a cart
If using the getCart query with customer impersonation tokens, you must include the cart’s entityId.
Request
Response
Add cart line items
Request
Response
Create a cart redirect URL
You can use a cart redirect URL for embedded checkouts or to redirect your
checkout. You need a cartEntity ID. To create a cartEntity ID, use the
create a cart mutation.
Request
Response
Create cart metafield
The current platform limit is 250 metafields for a single cart. When you create metafields using the createCartMetafield mutation, the default namespace is bc_storefront.
Request
Response
Delete cart
Request
Response
Get Checkout
Request
Response
Add checkout billing address
Request
Response
Add a checkout shipping consignment
Request
Response
Select checkout shipping option
Request
Response
Complete checkout
Request
Response
Giving feedback
We invite you to give feedback on the GraphQL Storefront schema and the capabilities of the API to let us know if it meets your needs. In particular, we want to know about anything that seems confusing, or anything that you think is missing. We want to ensure that this API meets your needs, and we’re open to adding features.
Join our Developer Community to share your feedback with us in the BigCommerceDevs Slack or on our Discord server.
Resources
Articles
- GraphQL Storefront API Overview
- Authenticating requests to the GraphQL Storefront API
- Payments API Overview
- Guide to API Accounts: Store-level API accounts
- Guide to API Accounts: OAuth token creation scopes
- Authentication and Example Requests: BigCommerce-generated JWTs