4

How to change quantity of product in cart using REST API in magento 2?

How can i change quantity of product listed in cart of magento 2 using api call ? (without changing order of items)

Fabian Blechschmidt
35.4k8 gold badges76 silver badges183 bronze badges
asked Oct 22, 2016 at 14:04

4 Answers 4

3

How to change quantity of product in cart using REST API ?

http://magento.host/index.php/rest/V1/carts/mine/items/{item_id}
  • method : **PUT**
  • Authorization : Bearer <customer token>

BODY

{
 "cartItem": {
 "sku": "MH11",
 "qty": 1,
 "quote_id": "3",
 "product_option": {
 "extension_attributes": {
 "configurable_item_options": [
 {
 "option_id": "93",
 "option_value": 58
 },
 {
 "option_id": "141",
 "option_value": 168
 }
 ]
 }
 },
 "extension_attributes": {}
 }
}

FROM HERE WE CAN EDIT CART ITEM (Like Qty, Attribute options etc.)

answered Oct 1, 2018 at 13:29
1
  • 1
    its adding new item to cart, not Changing Quantity Commented Jun 3, 2019 at 11:29
1

Regarding reducing qty you have to omit the product_options whilst doing the PUT request to the endpoint (rest/V1/carts/mine/items/{item_id}):

"cartItem": { "sku": "WSH05", "qty": 5, "quote_id": "3" } }

The problem with this is that it doesn't do any error checking / handling, so you can set any amount of stock even if it isn't available:

"cartItem": { "sku": "WSH05", "qty": 101, "quote_id": "3" } }

enter image description here

I have created a github issue to see if this is intended behaviour or whether we should actually get an error message. (https://github.com/magento/magento2/issues/12846)

answered Dec 21, 2017 at 14:07
1
  • 1
    still on it mate... Commented May 19, 2022 at 13:50
0

This is working for me to update (and overwrite, not increment) the quantity of an item in a guest cart via API call:

PUT V1/guest-carts/:cartId/items/:itemId

Body:

{
 "cartItem": {
 "item_id": :item_id, 
 "qty": :qty, 
 "quote_id": :cart_id_masked
 }
}

Perhaps the way item quantities were being incremented instead of overwritten is a bug that was fixed?

If you use the POST method, with a sku instead of item_id, then the quantity if incremented, I noticed. Not not when using PUT.

answered Jun 14, 2017 at 23:25
1
  • its adding new item to cart, not Changing Quantity Commented Jun 3, 2019 at 11:29
0

Assuming you want to change the quantity of a single item in a customer's cart, call:

POST V1/carts/mine/items

With a payload similar to

{
 "cartItem": {
 "item_id": 5,
 "qty": 4,
 "quote_id": "6"
 }
}
Chirag Patel
6,1662 gold badges26 silver badges66 bronze badges
answered Oct 24, 2016 at 18:03
3
  • 1
    if i call this it will add 4 quantities , and i call again it will add 4 quantities. its called adding. I not only want to increase quantities. i do want to decrease also. so, what should i do for decrease quantities in the cart. Commented Nov 27, 2016 at 18:39
  • 1
    Do you find a native solution for this ? Commented Mar 27, 2017 at 14:44
  • 1
    Do you find a solution ? Commented Apr 22, 2017 at 13:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.