Skip to content

How to update product attribute via Magento 2 API

I’m writing a Magento 2 client library in nodeJS and I’ve created some product attributes via this POST API /rest/V1/products/attributes which worked fine but I want to add update method as well, for which I tried this PUT API /rest/V1/products/attributes/{attributeCode} and it’s not letting me update the product attributes as this always returns with error: Attribute with the same code already exists.

Yes it exists already, that’s why I’m trying to update it. Following is the example request I’m making via Postman.

URL: https://MY_HOST/rest/V1/products/attributes/advantages

Body (JSON):

{
"attribute":{
  "frontend_input":"text",
  "attribute_code":"advantages",
  "default_frontend_label":"f max 1"
  }
}

It’s been many hours now and I still can’t figure out why it’s not updating, it seems like it tries to insert a new product attribute as I tried to pass attribute code which does not exists in magento and it created a new attribute with that code, which doesn’t seems right with PUT method. Any help in this regard would be highly appreciated.

Thanks & Regards.