1

I am trying to create the magento default REST API for add simple product to cart like this way.

  1. First I generate the customer token with the use of this API Call. https://www.domain.com/rest/default/V1/integration/customer/token And it will successful return the token.

  2. Now with the use of that token, I call another API to added the product to the existing cart like this : https://www.domain.com/rest/default/V1/carts/mine/items

    Headers:

    Content-Type: application/json

    Authorization: Bearer "CUSTOMER TOKEN"

And Pass the parameter as POST

{
    "sku": "PO-002",
    "qty": 1,
    "quote_id": "4"
}

And it always return the error like this :

{
    "message": "\"%fieldName\" is required. Enter and try again.",
    "parameters": {
        "fieldName": "cartItem"
    }
}

See the image :

enter image description here

Can any one help me here?

8
  • @Pawan how can I check this in postmen? I want to pass in body, right? Jan 7, 2021 at 12:24
  • please try: {cart_item:{ "sku": "PO-002", "qty": 1, "quote_id": "4" } }
    – Pawan
    Jan 7, 2021 at 12:25
  • in body parameter
    – Pawan
    Jan 7, 2021 at 12:25
  • It return error like this : "Server cannot understand Content-Type HTTP header media type text/plain" Jan 7, 2021 at 13:00
  • you need to set raw+JSON(application/json)
    – Pawan
    Jan 7, 2021 at 13:07

1 Answer 1

2

Please look at the example in the docs. The item should have a key named cartItem. Use the body to send a json that looks something like this:

{
    cartItem: {
        "sku": "PO-002",
        "qty": 1,
        "quote_id": "4"
    }
}

Your Answer

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

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