Magento2: PUT /V1/carts/{cartId}/items/{itemId} No such entity with cartId = null

Created on 15 Dec 2015  路  17Comments  路  Source: magento/magento2

Actual url

PUT /V1/carts/81/items/1

Post body

{
    "cartItem":{
        "qty":1
    }
}

Response

{
  "message": "No such entity with %fieldName = %fieldValue",
  "parameters": {
    "fieldName": "cartId",
    "fieldValue": null
  }
}
Ready for Work bug report

Most helpful comment

@userException To update the item in cart please try the following:
PUT /V1/carts/:cartId/items/:itemId

{
    "cartItem": {
        "itemId": 1,
        "qty": 10,
        "quoteId": 1
    }
}

You may obtain the list of items and their itemId for the specific cart using GET /V1/carts/:cartId/items.

All 17 comments

@pborges Thank you for reporting this.
Please try adding a quoteId param to the request body, e. g:

PUT /V1/carts/81/items/1
{
    "cartItem": {
        "qty": 10,
        "quoteId": 81
    }
}

We have an internal ticket with id MAGETWO-46732 to fix id duplication in such cases.

That did not work for me, this is the error I get now

{
  "message": "Cart %1 doesn't contain item  %2",
  "parameters": [
    "81",
    1
  ]
}

It looks like its trying to display that item rather than attach?
I am using a PUT request

@pborges PUT /V1/carts/:cartId/items/:itemId is used to update the item.
If you wish to add another item to the cart please refer to POST /V1/carts/:cartId/items.

Ok, I will try that. However the swagger documentation says

Put /V1/carts/{cartId}/items/{itemId}
description: "Adds the specified item to the specified cart."
operationId: "quoteCartItemRepositoryV1SavePut"

@pborges Thanks, we will check and fix documentation on this topic.

@pborges did you manage to solve this via post ? It give same response with post, as if it is trying to update the product

@pborges @userException
To add an item to the existing cart you may use the following:
POST /V1/carts/:cartId/items

{
    "cartItem": {
        "sku": "simple",
        "quoteId": 1,
        "qty": 1
    }
}

@userException post worked perfectly providing the item is "In Stock"

@pborges @ishakhsuvarov This worked for me..

Also, I was trying to update the product in the cart. How can I decrease the quantity? I tried sending -1 in "qty" parameter via a PUT request but it increased the quantity.

And deleting the product removes the whole product and does not decrease the quantity, which is correct. But what can be used for updating a product in the cart.

@userException To update the item in cart please try the following:
PUT /V1/carts/:cartId/items/:itemId

{
    "cartItem": {
        "itemId": 1,
        "qty": 10,
        "quoteId": 1
    }
}

You may obtain the list of items and their itemId for the specific cart using GET /V1/carts/:cartId/items.

@ishakhsuvarov @pborges Thanks this solved my issue ! Can you help me with this one: https://github.com/magento/magento2/issues/2773

@ishakhsuvarov the documentation here http://devdocs.magento.com/swagger/index.html still says "Implementation Notes Add the specified item to the specified cart." for the PUT method

how can we add configurable or bundle product to cart ?

Is there any update with this? I am working with Magento ver. 2.1.7.
If I try PUT '/V1/carts/{cartId}/items/10 with this body:

{
    "cartItem":{
        "qty":1,
        "quoteId": 70
    }
}

I get

{
    "message": "Cart %1 does not contain item %2",
    "parameters": [
        "70",
        10
    ]
}

PUT '/V1/carts/70/items/10' with this body:

{
    "cartItem":{
        "qty":1
    }
}

gets me this:

{
    "message": "No such entity with %fieldName = %fieldValue",
    "parameters": {
        "fieldName": "cartId",
        "fieldValue": null
    }
}

POST '/V1/carts/70/items/10' with this body:

{
    "cartItem": {
        "sku": "TRAINING-MAGENTO-STOREMG",
        "qty": 1
    }
}

gets me this:

{
    "message": "No such entity with %fieldName = %fieldValue",
    "parameters": {
        "fieldName": "cartId",
        "fieldValue": null
    }
}

So, basically, I haven't discovered a way to add an item to a cart.

In Post you need to include quoteId

Thanks for your help. What I had to do was:

  1. Create a cart
  2. Put the item in the cart

Details - Create Cart

POST '/V1/guest-carts'
(no body)

It returns something I will call a sCartKey. Mine looks like this: 8ea31b655a5ea0be566b9722f831b77a

Details - Add Item to Cart

To put iQty item(s) with the sku sSku in the cart:

POST '/V1/guest-carts/{sCartKey}/items'

with this body:

{
 "cartItem": {
   "sku" : sSku,
   "qty" : iQty,
   "quote_id" : sCartKey
 }
}

Hi I am still encountering the above error. I am using POST request with the following parameters in the body section
{"data":{"cartItem":{"productOption":{"extensionAttributes":{"customOptions":[]}},"qty":1,"quote_id":"1507026","sku":"FTW122019B3541","price":225}},"cartId":"1507026"}

And I get the following output
{ "message": { "message": "No such entity with %fieldName = %fieldValue", "parameters": { "fieldName": "cartId", "fieldValue": null } } }

Any help?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kandrejevs picture kandrejevs  路  3Comments

kirashet666 picture kirashet666  路  3Comments

MauroNigrele picture MauroNigrele  路  3Comments

salelsol picture salelsol  路  3Comments

BenSpace48 picture BenSpace48  路  3Comments