Magento – Add product to different website using rest API in magento 2

catalogmagento2restwebsites

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.

Best Answer

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
  }
}