0

Issue: Cannot add options to a product via API

I cannot add an option to a product via the Magento 2 REST API.

According to the API Documentation (http://devdocs.magento.com/swagger/index_20.html#/) AND under the title "catalogProductCustomOptionRepositoryV1"

I should be able to add an option using following format:

{
"option":{
  "productSku": "SomeExistingSKU",
  "optionId": 1,
  "title": "Size",
  "type": "drop_down",
  "sortOrder": 1,
  "isRequire": true,
  "max_characters": 0,
 "image_size_x": 0,
 "image_size_y": 0,
  "values": [
    {
      "title": "5",
      "sortOrder": 0
    }
  ],
  "extensionAttributes": {}
}

When I attempt to do this in POSTMAN for example I get the following message:

"message": "No such entity." 

The product already exists in Magento with the same SKU so that is not the problem

1 Answer 1

1

Solution is to remove the element "optionId": 1, from the input json. When you pass the value for the element option, the API looks for that option id and tries to update it. Since you want to add a new option you need to remove that.

Example:

{
"option":{
  "productSku": "someexistingproduct",
  "title": "Size",
  "type": "drop_down",
  "sortOrder": 1,
  "isRequire": true,
  "max_characters": 0,
 "image_size_x": 0,
 "image_size_y": 0,
  "values": [
    {
      "title": "5",
      "sortOrder": 0
    }
  ]
}}

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.