Magento 2 REST API – How to Add a Product to a Specific Store

magento2rest

I have two stores ("A" and "B"). Store "A" is selected as the default store. I want to add product "X" to store "B" using Magento 2's REST API.

I'm currently trying to do a POST request to http://localhost:8888/magento/index.php/rest/V1/products with the following JSON data:

{
   "product":{
      "sku":"3",
      "name":"Product X",
      "attribute_set_id":4,
      "price":1,
      "status":1,
      "visibility":4,
      "type_id":"simple"
   }
}

When doing this, the product gets added to the default store, which is store "A". My question is, how do I add a product to store "B" using the REST API?

I could not find anything in the docs about how to do this.

Best Answer

The answer seems to be quite simple. All you need to do is add the store code to the URL.

Example URL: http://localhost:8888/magento/index.php/rest/{store_code}/V1/products