0

I am calling this API to get product details:

GET https://domain.com/index.php/rest/V1/products/:SKU

and get this response:

<id>678</id>
  <sku>Mysku</sku>
  <name>myName</name>
  <attribute_set_id>4</attribute_set_id>
  <price>0</price>
  <status>1</status>
  <visibility>4</visibility>
  <type_id>configurable</type_id>
  <created_at>2017-04-23 15:01:05</created_at>
  <updated_at>2017-04-30 17:57:28</updated_at>
  <weight>0.1</weight>
  <extension_attributes>
    <configurable_product_options>
      <item>
        <id>38</id>
        <attribute_id>93</attribute_id>
        <label>Color</label>
        <position>0</position>
        <values>
          <item>
            <value_index>56</value_index>
          </item>
          <item>
            <value_index>61</value_index>
          </item>
          <item>
            <value_index>62</value_index>
          </item>
        </values>
        <product_id>678</product_id>
      </item>
    </configurable_product_options>
    <configurable_product_links>
      <item>675</item>
      <item>676</item>
      <item>677</item>
    </configurable_product_links>
  </extension_attributes>
....

I have a color in response. How can I add color option to cart. I tried with:

POST https://domain/rest/V1/guest-carts/3f9a39f1524fb936d932b7e80a3e8cc1/items

Params: {

"cartItem" :
{
"sku" : "Mysku",
"qty" : 1,
"quoteId" : "3f9a39f1524fb936d932b7e80a3e8cc1",

   "productOption":{
            "extensionAttributes":{
                "customOptions":[
                    {
                        "optionId":"38",
                        "optionValue":"56"
                    }
                    ]
            }
        }

}
}

And get this error:

message "You need to choose options for your item."

I think I have something wrong in parameters. can any one help ?

1 Answer 1

1

Perhaps it's because you're using the custom options object - you need to use the "configurable_item_options" object to pass through the configurable attributes.

{
  "cartItem": {
    "item_id": 0,
    "sku": "string",
    "qty": 0,
    "name": "string",
    "price": 0,
    "product_type": "string",
    "quote_id": "string",
    "product_option": {
    "extension_attributes": {
       "configurable_item_options": [
         {
          "option_id": "string",
          "option_value": 0,
          "extension_attributes": {}
        }
      ]
    }
  },
  "extension_attributes": {}
  }
}

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.