Skip to content

Update Cart Item

Change the quantity of a line already in the cart.

Endpoint

POST /api/shop/update-cart-item

Request Headers

HeaderRequiredDescription
Content-TypeYesapplication/json
X-STOREFRONT-KEYYesYour storefront API key
AuthorizationYesThe cart's own token as a Bearer token, or a logged-in customer's token.

Request Body

json
{
  "cartItemId": 372,
  "quantity": 4
}
FieldTypeRequiredDescription
cartItemIdintegerYesThe cart line id from items[].id — not the product id.
quantityintegerYesNew quantity. Must be 1 or more.

Both fields are required together, and the check rejects 0 as well as a missing value — the shared message is Cart item ID and quantity are required. Removing a line is a separate call, Remove Cart Item, not a quantity of zero.

Product options cannot be changed here. To switch a variant or an option selection, remove the line and add the product again with the new choice.

Response

201 Created carrying the whole recalculated cart — the same object Get Cart returns, plus success and message.

FieldTypeDescription
successbooleantrue when the call completed.
messagestringCart item updated successfully.
items[].quantityintegerThe new quantity on the updated line.
subtotal / grandTotal and their formatted* twinsnumber / stringRecalculated totals.

An unknown cartItemId also answers 201 with success: true and an unchanged cart — the call is a silent no-op rather than a 404. Verify by reading the line back from items.

Validation

RuleResult
cartItemId and quantity both present, quantity at least 1Otherwise 400 Cart item ID and quantity are required.
A Bearer token identifies the cartOtherwise 401 Authentication token is required.
Requested quantity is availableStock is enforced by the cart, which trims the line and reports the change in the returned totals.

Use Cases

  • Quantity stepper on the cart page — post the new quantity and re-render from the returned cart.
  • "Move to 1 before checkout" flows — the same call handles both increase and decrease.

Best Practices

  • Confirm the change from items, not from success — a wrong line id reports success while changing nothing.
  • Send the line id, not the product id — a product id normally matches no line and is silently ignored.
  • Use the remove endpoint for zero — quantity 0 is rejected as a missing value.
  • Re-render totals from the response — the payload is the full recalculated cart, so no follow-up fetch is needed.

Released under the MIT License.