Skip to content

Cart ​

The Cart menu is the shopping basket: create a cart, add and update items, remove items, and apply or remove a coupon. Every response returns the up-to-date cart with its items and recalculated totals, so a client never needs a separate refresh call after a change.

The cart token ​

A cart is identified by a cart token. Create a cart to obtain it, then send it as Authorization: Bearer <cartToken> on every subsequent cart request (and into checkout). The cart token works for both guests and logged-in customers — guests can build a cart without an account, and the same token carries the cart through checkout.

Coupons ​

Apply a coupon code to discount the cart, or remove it to revert. The cart totals in the response reflect the coupon immediately.

Merging a guest cart ​

When a shopper builds a cart as a guest and then logs in, merge the guest cart into their customer cart so nothing is lost. Call Merge Cart with the customer Bearer token and the guest cart's cart_id: items with the same product and type have their quantities added, other items are copied over, the guest cart is deactivated, and the response is the up-to-date customer cart. Merge requires an authenticated customer (401 for a guest) and a valid guest cart id (404 otherwise).

Body Field Names Differ Per Call ​

The cart endpoints do not share one naming convention, and sending the wrong key is read as a missing value rather than an error about the key:

CallFieldNot
Add to cartproductId, quantity—
Update itemcartItemId and quantity, both requiredquantity 0 is rejected; use Remove instead
Remove one itemcartItemIditemIds
Remove several itemsitemIds (array)cartItemId
Apply couponcouponCodecode

The item id in all of these is the cart line id from items[].id, never the product id. An unknown line id on Update answers 201 with success: true and changes nothing, so confirm the change by reading items back rather than trusting the flag.

What Comes Back ​

Every call returns the whole recalculated cart: items with per-line prices and totals, the subtotal / taxAmount / shippingAmount / grandTotal family with formatted* twins, the applied couponCode, and the checkout fields (billingAddress, shippingAddress, paymentMethod, selectedShippingRate) that fill in during checkout. Writes add success and message on top.

Because the payload is the full cart, re-render from the response — a follow-up read is never needed after a write.

Empty Carts and Failed Writes ​

Removing the last line leaves an empty cart, not a deleted one: the same cartToken keeps working and the shopper can carry on adding. A failed coupon is the one case where success matters — a wrong or non-qualifying code still answers 201 with the cart untouched, so branch on success, not on the status code.

Operations ​

Every cart write is a POST. There is no GET, PUT, or DELETE on this surface — reading the cart is a POST too, because the cart is identified by the token in the Authorization header rather than by a path parameter.

OperationMethod & PathDescription
Create CartPOST /api/shop/cart-tokensStart a cart and receive its token.
Get CartPOST /api/shop/cartRead the cart with its items and totals.
Add to CartPOST /api/shop/add-product-in-cartAdd a product of any type.
Update Cart ItemPOST /api/shop/update-cart-itemChange an item's quantity.
Remove Cart ItemPOST /api/shop/remove-cart-itemRemove one item.
Upload Customizable FilePOST /api/shop/customizable-option-filesAttach a file to a customizable option.
Apply CouponPOST /api/shop/apply-couponApply a coupon code.
Remove CouponPOST /api/shop/remove-couponRemove the applied coupon.
Merge CartPOST /api/shop/merge-cartsMerge a guest cart into the customer's cart after login.

There is also POST /api/shop/remove-cart-items, which takes an itemIds list and removes several lines in one call.

Every one of these returns the updated cart as a bare object, so a client can re-render from the response without a follow-up read.

All Cart endpoints require the storefront key and a cart token (issued by Create Cart) — see Authentication.

Released under the MIT License.