1

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.

1
  • For anyone like me wondering how to add a product in multiple stores, see this answer (spoiler: you still need two API calls).
    – bfontaine
    Commented Aug 26 at 14:04

1 Answer 1

3

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

1
  • I created custom API to update details but I want to update detail based on store code and store code is collected from payload any idea? Commented May 14, 2020 at 7:16

Your Answer

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

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