Skip to main content
The cart lives on the server: in the guest session, or on the account when the customer is logged in. You read it with GET /cart and you write it with POST /cart/quote, which saves the cart first and then prices it.
POST /cart/quote replaces the whole stored cart with the body you send. Always send the full cart: lines, promotion codes, gift choices, email, destination and shipping method. A field you leave out is cleared. The safe pattern is: read the cart, change it, send it back.
Session: guest or login, following the mode. Rate limit: cart.quote.

Get the Cart

GET /cart Returns the stored cart, not priced. A new session returns the empty cart.
Response 200

Quote the Cart

POST /cart/quote Unknown fields are ignored.
Request
Response 200
How to read the quote: Errors: 400 with a field code (required, invalid, too_many, too_long, invalid_country, invalid_email, invalid_locale); 400 VARIANT_UNAVAILABLE on lines.<i>.variantId (unknown or inactive variant); 400 INSUFFICIENT_STOCK on lines.<i>.quantity; 400 SHIPPING_UNAVAILABLE on shipping (the method does not serve the destination or cannot take the cart); 401 SESSION_INVALID, LOGIN_REQUIRED, CUSTOMER_SESSION_INVALID; 429 RATE_LIMITED.
Strapi saves the cart before it prices it. When a quote fails with VARIANT_UNAVAILABLE or INSUFFICIENT_STOCK, the cart is already stored. Read it back with GET /cart, point the customer at the line in errors[].path, and let them lower the quantity or remove the line.

Cart Server Actions

src/lib/store/cart.ts
src/app/(store)/cart/actions.ts
src/app/(store)/shop/products/[slug]/add-to-cart.tsx
The cart page reads the stored cart and prices it on every render. It never opens a session: a visitor without a cookie simply has an empty cart.
src/app/(store)/cart/page.tsx
When a quote fails with a stock error, render the stored cart lines (from GET /cart) next to the messages from errors[].path instead of throwing, so the customer can fix the cart.