Skip to content

Create Cart ​

Start a shopping cart and obtain the cart token that identifies it. A guest client calls this once at the beginning of a session and reuses the returned token for every subsequent cart and checkout call.

Endpoint ​

POST /api/shop/cart-tokens

The path is /cart-tokens, not /cart — /api/shop/cart is the read endpoint documented on Get Cart.

Request Headers ​

HeaderRequiredDescription
Content-TypeYesapplication/json
AcceptYesapplication/json
X-STOREFRONT-KEYYesYour storefront API key
AuthorizationNoA signed-in customer's Bearer token, to tie the cart to their account

Request Body ​

Send an empty object. The endpoint takes no fields — items are added afterwards with Add to Cart.

json
{}

Response Fields ​

The response is the newly created cart, returned as a bare object with no wrapper.

FieldTypeDescription
idintegerCart ID.
cartTokenstringSend this as Authorization: Bearer <cartToken> on every later cart call.
customerIdintegerOwning customer, or null for a guest cart.
channelIdintegerChannel the cart belongs to.
itemsCountintegerNumber of line items. 0 on a new cart.
itemsQtyintegerTotal units across those lines.
itemsarrayLine items — empty on a new cart.
subtotal / baseSubtotaldecimalItems subtotal, in cart and base currency.
discountAmount / baseDiscountAmountdecimalDiscount applied.
taxAmount / baseTaxAmountdecimalTax calculated.
shippingAmount / baseShippingAmountdecimalShipping cost.
grandTotal / baseGrandTotaldecimalGrand total.
formattedSubtotal, formattedDiscountAmount, formattedTaxAmount, formattedShippingAmount, formattedGrandTotalstringThe same amounts, currency-formatted for display.
couponCodestringApplied coupon, or null.
isGuestbooleanWhether the cart belongs to a guest.

Use Cases ​

  • Start a guest session — call once, store cartToken, and send it on every cart and checkout request.
  • Start a signed-in session — send the customer's Bearer token as well, so the cart is tied to their account and survives across devices.

Best Practices ​

  1. Store the cartToken, not the cart id — the token is what authenticates later calls; the numeric ID is informational
  2. Create the cart once per session — calling again issues a new empty cart and orphans the previous one
  3. Merge after login — a guest who signs in mid-session should call Merge Cart so their items survive
  4. Expect an empty cart, not an error — a newly created cart has itemsCount: 0 and zeroed totals
  • Get Cart — read the current items and recalculated totals
  • Add to Cart — add a product of any type to the cart
  • Merge Cart — fold a guest cart into the customer's cart after login

Released under the MIT License.