3

I have json array for attribute options which is showing below:

"options":[
 {
  "label":"string",
  "value":"string",
  "sort_order":0,
  "is_default":true,
  "store_labels":[
   {
    "store_id":0,
    "label":"string"
   }
  ]
 }
],

So I need that types of data by the magento 2 collection for particular attribute id or code.

I need to add/edit attribute options data using rest api in magento 2

Please provide me collection, thanks in advance.

1

First of all, we need take a look: Log in Magento Admin > Choose a product > ADVANCED SETTINGS > Custom Options:

enter image description here

We can see some fields, we need to fill in these input fields.

Second, we have the APIs for updating the custom options: http://devdocs.magento.com/swagger/#resource_catalogProductCustomOptionRepositoryV1

  • POST: /V1/products/options

  • PUT: /V1/products/options/{optionId}

For example:

{
  "option": {
    "product_sku": "string",
    "option_id": 0,
    "title": "string",
    "type": "string",
    "sort_order": 0,
    "is_require": true,
    "price": 0,
    "price_type": "string",
    "sku": "string",
    "file_extension": "string",
    "max_characters": 0,
    "image_size_x": 0,
    "image_size_y": 0,
    "values": [
      {
        "title": "string",
        "sort_order": 0,
        "price": 0,
        "price_type": "string",
        "sku": "string",
        "option_type_id": 0
      }
    ],
    "extension_attributes": {}
  }
}
  • product_sku: Product SKU

  • option_id: We can get by /V1/products/{sku}/options

  • title: Title of the custom option.

  • type: Input Type: Text, File, Dropdown, Radio, etc

  • sort_order: Set the order of custom attribute

  • is_require: Required or not

  • price: Price for the custom option

  • price_type: Fixed or Percent

  • sku: (updated later)

  • file_extension: can be empty, allowed file types: pdf, jpg, ...

  • max_characters: can be empty, used for Input type: Field, Area.

  • image_size_x and image_size_y: blank if it is not an image.

  • values: can be empty, used for Select Type: Dropdown, Radio Buttons, Checkbox, Multiple Select. We need to set the title, price type, Sortorder, etc.

  • How can i get options images, dependency to custom option in rest api I am using Mageworx product option extension for adding extra product option like images and dependency???? – Kirti Nariya Oct 17 at 7:17

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.