End-to-End Guide: Headless checkout flow with the GraphQL Storefront API
End-to-End Guide: Headless checkout flow with the GraphQL Storefront API
End-to-End Guide: Headless checkout flow with the GraphQL Storefront API
The BigCommerce GraphQL Storefront API lets server-side and browser-side clients manage product, cart, and checkout objects to build storefront features. The GraphQL Storefront API can solve the same use cases as our REST Management API’s cart and checkout features, but makes it easier to build headless storefront applications. Developers using the GraphQL Storefront API can spend less time focusing on API interactions and more time building the shopper experience.
This end-to-end guide describes how to work with shopper interactions on headless storefronts. These steps let you build shopping experiences where the purchase funnel is mainly powered by the GraphQL Storefront API, from catalog browsing through checkout. The examples walk you through critical capabilities that fit many headless use cases.
You can use the GraphQL Storefront API playground to run the example queries in this guide. To access your store’s GraphQL Storefront API playground, sign in to your store, and navigate to Settings > API > Storefront API Playground.
To complete the guide, you need the following:
You can make requests to the GraphQL Storefront API in a server-to-server context. This guide describes creating and using a customer access token to authenticate and use the GraphQL Storefront API.
A customer access token is unique to an individual user’s account. To generate a customer access token, enter your GraphQL variables (user email and password) and run the login mutation.
In a tool like Postman or Altair, add the customer access token to the Headers tab as follows. For more information, see Using a Customer Access Token.
The GraphQL Storefront API lets you retrieve product data from a store. The following example demonstrates how to query a simple product using the GraphQL Storefront API. Pricing and visibility response values can vary based on the customer. For more information and examples, see the Guide to working with products.
When possible, use the following best practices for queries to the GraphQL Storefront API.
BigCommerce’s GraphQL Storefront API provides the same cart and checkout objects as the REST Storefront API. Pricing and visibility response values can vary based on the customer. The following example shows how to create a new cart by adding a simple product.
Make note of one of the cart’s entityId displayed in the response. You will need to use it in later steps.
To add a new line item to the existing cart, add the cart ID to the input variables or the mutation will fail.
The following query example shows how to display the contents of a checkout.
You can access cart and checkout details in the same request as other information. The cart ID is the same as a checkout ID.
This mutation adds a billing address to an existing checkout.
This mutation adds a shipping consignment to an existing checkout.
Make a note of a shipping consignment’s entityId and the desired shipping option’s entityId returned from your request. You will need to use these in later steps.
This mutation adds a selected shipping to an existing checkout.
Completing a checkout creates an incomplete order until you process the payment. For PCI compliance-related reasons, the GraphQL Storefront API does not handle payments. You must use the Payments API to process payments. The payments workflow includes the following three steps: