End-to-End Guide: Headless checkout flow with the REST Management API
This tutorial walks you through creating a cart, checkout, an order, and processing a payment using the Carts and Checkout REST Management APIs to build a headless storefront.
This article assumes you are familiar with the following:
- Creating a channel and a site.
- Retrieving product data using REST Management API calls
Prerequisites
- A store-level or app-level API account with the following permissions:
For more information, see OAuth Scopes.
Creating a cart
Step 1: Generate the cart ID
To generate a cart ID, send a request to the Create a cart endpoint. The response contains an id, which is the cart_id or cartId in subsequent calls.
Request
Response
Step 2: Generate the redirect URLs
After you generate the cart ID, generate URLs to redirect customers to the BigCommerce-hosted cart and checkout pages.
To generate the redirect URLs, send a request to the Create a cart redirect URL endpoint. You use the cart ID generated in Step 1. The response contains the cart_url and the checkout_url.
Request
Response
Creating a checkout
After you create a cart, transform it into a checkout by adding a billing address. You must have a checkoutId, which is the same as the cart_id you generated in Step 1 of creating a cart. To add a billing address, send a request to the Add Checkout Billing Address endpoint.
Request
Response
After you transform your headless cart into a proper checkout with a billing address, you can add a consignment with a shipping address, line items, and a shipping option. You can do so using the following two-step process:
Step 1: Add a new consignment to the checkout
Send a request to the Add Consignment to Checkout endpoint. Append the include=consignments.available_shipping_options query parameter to your request to return available shipping options. Use one of the available shipping options to update the consignment in step 2.
Request
Response
The response contains an array of available_shipping_options. In the next step, use one of the available shipping options to update the consignment.
Step 2: Update the consignment with a shipping option
After you create the consignment, update it with one of the available shipping options the previous request returned. Send a request to the Update Checkout Consignment endpoint.
Request
Response
Creating an order
After you add a billing address and a consignment to your checkout, you can create an order by sending a request to the Create an Order endpoint. The initial order status is incomplete.