How to add item to cart in magento 2 API

First of all empty cart should be created using request with empty body:

[POST] {base URL}/rest/V1/carts/mine

In response you will get ID of your cart/quote. Now you can add items to your cart using:

[POST] {base URL}/rest/V1/carts/mine/items{  "cart_item": {    "quote_id": ,    "sku": "product_sku",    "qty": 10  }}

In response you should get your cart item data:

{  "item_id": 1,  "sku": "product_sku",  "qty": 10,  "name": "Simple Product",  "price": 123,  "product_type": "simple",  "quote_id": "1"}

Be careful since you may accidentally update existing cart item quantity with POST request, if execute the same request several times.

Leave a Reply

Your email address will not be published. Required fields are marked *