6

I Have this problem when trying to add a product to cart:

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

My API:

POST on:

https://domain.com/rest/V1/guest-carts/ce7b9f063fb07fcb03d71a2eff922d8d/items?cartItem[sku]=1508110&cartItem[qty]=1&cartItem[quote_id]=353
  • ce7b9f063fb07fcb03d71a2eff922d8d is the cart-key which I got through API:

    POST http://domain.com/rest/V1/guest-carts

  • quote_id = 353 is the id which I got from cart details through API:

    GET http://domain.com/rest/V1/guest-carts/ce7b9f063fb07fcb03d71a2eff922d8d

Please help.

1 Answer 1

5

You can refer to the offical swagger documentation : http://devdocs.magento.com/swagger/index_20.html#/

1/ You need to create a guest cart :

POST http://domain.com/rest/V1/guest-carts

Which return a guest cart id such as 881d962b14c14764a0f5939be4722cbc.

2/ (Optional) Retrieve the quote id from this API call :

GET http://domain.com/rest/V1/guest-carts/881d962b14c14764a0f5939be4722cbc

Where a field id correspond to the quote id, for example "id": 31.

3/ Add a product to your cart :

POST http://domain.com/rest/V1/guest-carts/881d962b14c14764a0f5939be4722cbc/items

The payload pattern is :

{
  "cartItem": {
    "itemId": 0,
    "sku": "string",
    "qty": 0,
    "name": "string",
    "price": 0,
    "productType": "string",
    "quoteId": "881d962b14c14764a0f5939be4722cbc",
    "productOption": {
      "extensionAttributes": {
        "customOptions": [
          {
            "optionId": "string",
            "optionValue": "string",
            "extensionAttributes": {
              "fileInfo": {
                "base64EncodedData": "string",
                "type": "string",
                "name": "string"
              }
            }
          }
        ],
        "downloadableOption": {
          "downloadableLinks": [
            0
          ]
        },
        "giftcardItemOption": {
          "giftcardAmount": 0,
          "customGiftcardAmount": 0,
          "giftcardSenderName": "string",
          "giftcardRecipientName": "string",
          "giftcardSenderEmail": "string",
          "giftcardRecipientEmail": "string",
          "giftcardMessage": "string",
          "extensionAttributes": {}
        },
        "configurableItemOptions": [
          {
            "optionId": "string",
            "optionValue": 0,
            "extensionAttributes": {}
          }
        ],
        "bundleOptions": [
          {
            "optionId": 0,
            "optionQty": 0,
            "optionSelections": [
              0
            ],
            "extensionAttributes": {}
          }
        ]
      }
    },
    "extensionAttributes": {}
  }
}

An example for a basic configurable product :

{
  "cartItem": {
    "sku": "ProductSKU",
    "qty": 1,
    "quoteId": "881d962b14c14764a0f5939be4722cbc",
    "productOption": {
      "extensionAttributes": {
        "configurableItemOptions": [
          {
            "optionId": "178",
            "optionValue": 45,
            "extensionAttributes": {}
          }
        ]
      }
    }
  }
}

Magento uses both cartId and quoteId that referece on different internal id.

7
  • you can use postman as an alternative or soap ui for a more robust software. Commented Mar 13, 2017 at 13:39
  • In HTTP requester addon, set the POST payload in the content form with application/json content type Commented Mar 13, 2017 at 13:49
  • Still got the same error
    – Jsparo30
    Commented Mar 13, 2017 at 14:00
  • I just updated my answer, use the long cartId for the POST payload : for example 881d962b14c14764a0f5939be4722cbc . Sorry for the mistake. Commented Mar 13, 2017 at 14:21
  • @FranckGarnier How can I get the optionId and optionValue as a guest user? Commented Apr 10, 2018 at 9:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.