Magento – Add product to guest cart with custom option and its price in Magento 2 api

apicartcustom-optionsmagento2

I need to add product in cart using magento 2 api.

I am using below api

"rest/V1/guest-carts/{cart_id}/items

I am passing parameters like below,

    {
    "cartItem": {
        "sku": "paneer_chilli-1",
        "qty": "1",
        "name": "Paneer Chilli",
        "price": 100,
        "product_type": "simple",
        "quote_id": "3a43e2fc1ed26db195a8ceee00929bcb",
        "product_option": {
            "extension_attributes": {
                "custom_options": [{
                    "option_id": 6,
                    "option_value": 2
                }]
            }
        }
    }
}

dosent work, it is giving error like below,

Property "CustomOptions" does not have corresponding setter in class "Magento\Quote\Api\Data\CartItemExtensionInterface".

What is option_id and option_value in my case when I have to pass custom option with multiple option with its price (checkbox)

It will be great if someone can help.
Thanks

Best Answer

Go to http://devdocs.magento.com/swagger/ > quoteGuestCartItemRepositoryV1

In your case, should change to underscore format

{
    "cartItem": {
        "quote_id": {cart id},
        "sku": {sku},
        "qty": 1,
        "product_option":{
            "extension_attributes":{
                "custom_options":[
                    {
                        "option_id":"1",
                        "option_value":"2"
                    }
                    ]
            }
        }
    }
}