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.

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

The following request updates the line item identified by the "aBmNkPQRst" ID with a quantity of 6:

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
    }
  }
}'

Mapping

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

More to read

See our documentation if you need more information on how to update a line item.

Last updated