> ## Documentation Index
> Fetch the complete documentation index at: https://docs.launchmystore.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Cart

> Update cart items or attributes

# Update Cart

Updates quantities of items in the cart, or updates the cart note,
attributes, and discount codes.

<Note>
  Cart update is a **storefront** surface, not part of the OAuth `/api/v1` app
  API. It follows the Shopify-AJAX cart contract: requests are made against the
  storefront origin (your store domain), identity is the `cart` cookie token
  (not a Bearer access token), and the response is the **flat** Shopify cart
  object — not wrapped in a `{ status, type, data }` envelope.
</Note>

## Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://your-store.launchmystore.io/cart/update.js" \
    -H "Content-Type: application/json" \
    -H "Cookie: cart=c1-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" \
    -d '{
      "updates": {
        "639664": 3,
        "640001": 0
      }
    }'
  ```

  ```javascript Browser (fetch) theme={null}
  const response = await fetch('/cart/update.js', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      updates: {
        "639664": 3,
        "640001": 0  // Remove item
      }
    })
  });
  const cart = await response.json();
  ```
</CodeGroup>

## Body Parameters

<ParamField body="updates" type="object">
  Object mapping variant IDs to new quantities. Set a quantity to `0` to
  remove that item.
</ParamField>

<ParamField body="note" type="string">
  Update the cart note
</ParamField>

<ParamField body="attributes" type="object">
  Update cart attributes (replaces existing attributes)
</ParamField>

<ParamField body="discount" type="string">
  Discount code(s) to apply. Accepts a single code or comma-separated codes.
  Pass an empty string to clear all applied discount codes.
</ParamField>

## Response

The response is the flat Shopify cart object (the same shape returned by
[Get Cart](/api-reference/cart/get)), reflecting the updated cart. For
quantity updates the response also includes an `items_changelog` object
(`{ added, removed }`).

## Example Response

```json theme={null}
{
  "token": "c1-9a3f0c2e-7b1d-4e8a-9f2c-1a2b3c4d5e6f",
  "items": [
    {
      "key": "639664:default",
      "id": 639664,
      "product_id": 12001,
      "variant_id": 639664,
      "title": "Classic T-Shirt",
      "variant_title": "Medium / Black",
      "quantity": 3,
      "price": 2500,
      "line_price": 7500,
      "sku": "TSHIRT-M-BLK"
    }
  ],
  "item_count": 3,
  "total_price": 7500,
  "currency": "USD",
  "note": "",
  "attributes": {},
  "items_changelog": {
    "added": [{ "id": 639664, "quantity": 3 }],
    "removed": [{ "id": 640001 }]
  }
}
```

## Updating Cart Note, Attributes, and Discounts

```json theme={null}
{
  "note": "Please gift wrap this order",
  "attributes": {
    "gift_message": "Happy Birthday!",
    "preferred_delivery_date": "2024-03-25"
  },
  "discount": "SUMMER10"
}
```

## Errors

On failure the endpoint returns a Shopify-style error body with the real HTTP
status:

```json theme={null}
{
  "status": 422,
  "message": "Requested quantity exceeds available stock",
  "description": "Requested quantity exceeds available stock"
}
```
