Magento – Magento 2.2 REST API Add Item to cart issue

apicartrest

i have an issue with Magento ver. 2.2.0-dev i'm trying to create a cart and insert a product for a logged user, with the magento 2 rest api, but when i try to insert a product into the cart (already correctly created) it seems doesn't work and respond with this error:

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

Steps to reproduce:

  • Create a cart with get rest/V1/carts/mine

  • Call the rest api for
    insert product in the cart with the correct token of the user at rest/V1/carts/mine/items

  • Headers: Authorization Bearer + [TOKEN]

  • Body: cartItem: testing (sku of the product); qty: 1

Expected Result

  • a 200 status and the json of the cart

Actual Result

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

How can i solve?? it's a bug or i forgot something? i've seen a lot of thread but no one can help me.

Thanks in advance!

Best Answer

SOLVED!

In postman, we was selecting 'form-data', but you have to select 'raw' and insert a json object like this:

{
  "cart_item": {
    "quote_id": 5,
    "sku": "testing2",
    "qty": 1
  }
}

that should work! hope it helps.