> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/how-tos/placing-orders/shopping-cart/update-quantity.md).

# Updating cart quantities

How to update the quantity of an item in your shopping cart

## Problem

You have some items in your shopping cart and you want to update their quantity.

![A sample cart quantity selection](https://2610849379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lk-ezuDClaMavTqnRi0%2Fuploads%2F6oFVrpjv2A48tyYPTfFx%2Fupdate-cart-quantities-cover.jpg?alt=media\&token=a4710319-0aaa-43da-b314-1db8a396bac0)

## Solution

To set the quantity of an item in your shopping cart you need to change its `quantity` attribute. To do that, send a `PATCH` request to the `/api/line_items/:id` endpoint.

### Example

{% tabs %}
{% tab title="Request" %}
The following request updates the line item identified by the "aBmNkPQRst" ID with a quantity of 6:

```javascript
curl -g -X PATCH \
  'http://yourdomain.commercelayer.io/api/line_items/aBmNkPQRst' \
  -H 'Accept: application/vnd.api+json' \
  -H 'Authorization: Bearer your-access-token' \
  -d '{
  "data": {
    "id": "aBmNkPQRst",
    "type": "line_items",
    "attributes": {
      "quantity": 6
    }
  }
}'
```

{% endtab %}

{% tab title="Response" %}
On success, the API responds with a `200 OK` status code, returning the line item object updated with the new quantity:

```javascript
{
  "data": {
    "id": "aBmNkPQRst",
    "type": "line_items",
    "links": {
      "self": "https://yourdomain.commercelayer.io/api/line_items/aBmNkPQRst"
    },
    "attributes": {
      "sku_code": "TSHIRTB5B5B5XL",
      "quantity": 6,
      "currency_code": "EUR",
      "unit_amount_cents": 12900,
      "unit_amount_float": 129.0,
      "formatted_unit_amount": "129,00€",
      "options_amount_cents": 0,
      "options_amount_float": 0.0,
      "formatted_options_amount": "$0.00",
      "total_amount_cents": 77400,
      "total_amount_float": 774.0,
      "formatted_total_amount": "774,00€",
      "name": "Grey T-Shirt XL",
      "image_url": "https://img.yourdomain.com/skus/TSHIRTB5B5B5XL.png",
      "tax_rate": null,
      "tax_breakdown": {},
      "item_type": "skus",
      "created_at": "2018-01-01T12:00:00.000Z",
      "updated_at": "2018-01-01T12:00:00.000Z",
      "reference": null,
      "metadata": {}
    },
    "relationships": {
      "order": {
        "links": {...}
      },
      "item": {
        "links": {...}
      },
      "line_item_options": {
        "links": {...}
      }
    },
    "meta": {
      "mode": "test",
      "organization_id": "Qr8sStTuUv",
      "trace_id": "0a3b6c9d2e5f8a1b4c7d0e3f6a9b2c5d8e1f4a7b0c3d6e9f2a5b8c1d4e7f0a3b6"
    }
  },
  "meta": {
    "mode": "test",
    "organization_id": "Qr8sStTuUv",
    "trace_id": "0a3b6c9d2e5f8a1b4c7d0e3f6a9b2c5d8e1f4a7b0c3d6e9f2a5b8c1d4e7f0a3b6"
  }
}
```

{% endtab %}
{% endtabs %}

### Mapping

The image below shows how the related action on the product quantity is mapped to a specific attribute of the line item object.

![A sample cart quantity update mapping](https://2610849379-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lk-ezuDClaMavTqnRi0%2Fuploads%2FbCjus91E5uomI6hvJFLr%2Fupdate-cart-quantities-mapping.jpg?alt=media\&token=01810ec1-ea37-4841-888d-98f86d0ee2ad)

## More to read

See our documentation if you need more information on how to [update a line item](https://docs.commercelayer.io/developers/v/api-reference/line_items/update).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.commercelayer.io/how-tos/placing-orders/shopping-cart/update-quantity.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
