Magento 2 – How to Update Value and Label in Attribute REST API

magento2rest api

I have an attribute manufacturers, it has a value, I want to select them and change which I need using Rest API

I tried sending a request like this

http://magengree/rest/V1/products/attributes/manufacturer/1/options

i got this Response

Response {
    "message": "Request does not match any route."
}

How can I do that ?

Best Answer

You are accessing wrong URL. Please see the details below.

Get all available options for product attribute

Request Method : GET

Request Link Syntax : <base_url>/rest/V1/products/attributes/<attribute_code>/options

Request Link in your case : http://magengree/rest/V1/products/attributes/manufacturer/options

Add new option for product attribute

Request Method : POST

Request Link Syntax : <base_url>/rest/V1/products/attributes/<attribute_code>/options

Request Link in your case : http://magengree/rest/V1/products/attributes/manufacturer/options

Request Body : JSON(application/json)

{
  "option": 
        {
              "label": "Apple",
              "value": "214",
              "sort_order": 0,
              "is_default": true,
              "store_labels": [
              {
                  "store_id": 0,
                  "label": "Apple3"
              }
              ]
        }
}

Delete any existing option for product attribute

Request Method : DELETE

Request Link Syntax : <base_url>/rest/V1/products/attributes/<attribute_code>/options/<option_id>

Request Link in your case : http://magengree/rest/V1/products/attributes/manufacturer/options/214

Make sure you add Authorization token for all request.

For more information Refer catalogProductAttributeOptionManagementV1 from https://devdocs.magento.com/swagger/

Hope it finds you helpful.