Home > database >  Magento 2 Rest API Can't Remove Category ID's from product
Magento 2 Rest API Can't Remove Category ID's from product

Time:09-18

I am working on a REST API call which will remove the category ID from a live product. The below code returns true but this has not updated in the back end or on the site.

I have followed the magento documentation for the update request and that works well, I tried doing the inverse of that with the delete request and following some examples online.

The below method is DELETE.

If someone can advise how this category can be removed then please advise.

{
"product": {
"sku": "MRO2222",
"status": "0",
  "category_links": [
    {
      "position": 100,
      "category_id": "8"
    }
  ]
}

}

CodePudding user response:

Unfortunately there doesn't seem to be a proper way through a delete request with Magento Rest API.

The way to go is to unset the categories of the product and update with the desired categories afterwards.

You can unset the categories with a PUT request to endpoint: https://www.yoursite.com/rest/all/V1/products/your_product_sku (replace url and sku)

with payload:

{  
   "product":{  
      "extensionAttributes":{  
         "category_links":[  
            
         ]
      }
   }
}
  • Related