2

Hi I am trying to add configurable product add to cart using REST API in magento 2.1.8. but its getting

{ "message": "You need to choose options for your item." }

Note:- For logged in users i am trying to add.

{
   "cartItem": {
      "quote_id": "308",
      "sku": "WSH12",
      "qty": "1",
      "product_option": {
         "extension_attributes": {
           configurable_item_options [
               {
                  "option_id": "", 
                  "option_value": ""
               }, {
                  "option_id": "", 
                  "option_value": ""
               }
            ]
         }
      }
   }
}

Screen shots:-

enter image description here

enter image description here

enter image description here

  1. Please clarify how to consider option_id an option_value? what exact values need to consider as per this example?
  2. Is it default magento 2 api issue?
  • Did you solve this issue? – Nitesh Aug 24 '18 at 10:17
  • yes i have followed below post – Nagaraju Kasa Aug 24 '18 at 10:21
  • I also tried it, but no success, but difference is I am not trying with json format, I am using array format. – Nitesh Aug 24 '18 at 11:05
4

If you do a GET (rest/V1/products/YOURSKU) on the required item, you can see what the option_value / option_id are.

For an example product on my store -

"configurable_product_options": [
        {
            "id": 84,
            "attribute_id": "186",
            "label": "Subscription Term",
            "position": 0,
            "values": [
                {
                    "value_index": 137
                },
                {
                    "value_index": 133
                },
                {
                    "value_index": 134
                },
                {
                    "value_index": 135
                },
                {
                    "value_index": 136
                }
            ],

With this, the POST would be -

{
 "cart_item": {
 "quote_id": 193,
 "product_type" : "configurable",
 "sku": "YOURSKU",
 "qty": 1,
 "product_option": {
     "extension_attributes": {
       "configurable_item_options" : [
           {
              "option_id": "186", 
              "option_value": 137
           }
     ]
     }
   }
  }
 }
  • @thanks BigDaddyl i will check and get back to you thanks for the quick response – Nagaraju Kasa Nov 7 '17 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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