1

I want to update sku using Rest API in magento 2 Call:

PUT /rest/V1/products/{sku}

Request:
{
"product": {
"sku": "modified.sku",
"name": "modified name"
}
}

Result: The name has changed, but the sku is the same. How can I change the product sku?

1

2 Answers 2

1

SKU is a unique key for products. It can't be changed via the API.

1
  • I initially upvoted this answer but it turns out it’s wrong, as you can verify by using the code in mydons’ answer.
    – bfontaine
    Mar 10 at 11:02
1

You can update the SKU using the below request format. Since there is a bug in magento which doesn't update the new values for some store views. You can use the below Request URL and Request JSON.

PUT: rest/all/V1/products/{sku}.

{
  "saveOptions": "true",
  "product": {
    "id": 1,
    "sku": "modified.sku",
    "name": "modified.name",
    "attribute_set_id": your_attribute_set_id,
    "price": 34,
    "status": 1,
    "visibility": 4,
    "type_id": "simple"
   }
 }
1
  • The key is to add "id" and "saveOptions". It doesn't work when "saveOptions" is not added but works even if it's set true or false!
    – palindrom
    Mar 5, 2021 at 6:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.