I want to add product to different website in magento 2 using rest api. I am able to add product to the store but I am not getting any information as how to add product to different websites inside magento.
2 Answers
As far as I know, this cannot be done in the initial adding of the product through the API (it will always be added just to your default website), but you can then use the API to add it to other websites.
Documentation on catalogueProductWebsiteLinkRepositoryV1
Send a POST
request to /V1/products/{sku}/websites
(changing {sku}
for the item's sku).
For the body of the request, use the format:
{
"productWebsiteLink": {
"sku": "{your-sku-again}",
"website_id": {numeric-id-of-website}
}
}
e.g.
{
"productWebsiteLink": {
"sku": "1234",
"website_id": 2
}
}
In addition to Luke Cousins answer, I'd like to point out that "Use default value" on the default store view gets deselected as soon as you link the product to a non-default website via /V1/products/{sku}/websites
.
I haven't found a way to solve this problem.