Skip to content

Remove Cart Item

Remove one line from the cart, or several in a single call.

Endpoints

PurposeMethod & PathBody field
Remove one linePOST /api/shop/remove-cart-itemcartItemId (integer)
Remove several linesPOST /api/shop/remove-cart-itemsitemIds (array of integers)

The two endpoints use different body field namescartItemId on the singular route, itemIds on the plural one. Sending the wrong one is read as a missing value and rejected with 400.

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": 369
}
FieldTypeRequiredDescription
cartItemIdintegerYesThe cart line id, from items[].id on the cart payload — not the product id.

For the bulk route:

json
{
  "itemIds": [370, 371]
}
FieldTypeRequiredDescription
itemIdsarrayYesCart line ids. An empty array is rejected.

Response

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

FieldTypeDescription
successbooleantrue when the line or lines were removed.
messagestringItem removed from cart successfully, or the plural form on the bulk route.
itemsarrayThe remaining lines. Empty once the last one is gone.
grandTotal and the other totalsnumberRecalculated after the removal.

Removing the last line leaves an empty cart rather than deleting it — the same cartToken keeps working, so the shopper can carry on adding.

Use Cases

  • "Remove" on a cart line — post the line id and re-render from the returned cart; no follow-up fetch is needed.
  • "Clear cart" — collect every items[].id and send them to the bulk route in one call instead of looping the singular one.
  • Remove out-of-stock lines before checkout — the bulk route takes exactly the ids a stock check flagged.

Best Practices

  • Send the cart line id, not the product id — they differ, and a product id usually matches no line, so nothing is removed.
  • Match the field name to the routecartItemId singular, itemIds plural; mixing them produces a 400 that reads as a missing field.
  • Re-render from the response — it is the full recalculated cart, including totals and any coupon still applied.
  • Do not recreate the cart after removing everything — the token stays valid on an empty cart.

Released under the MIT License.