The REST API documentation says that PUT /V1/products/{sku} creates rather than updates.
Is that an error in the docs because I would have assumed that it is an update method and POST being the method to create?
3 Answers 3
POST and PUT route to same method save, but with POST you cannot pass sku
 <route url="/V1/products" method="POST">
 <service class="Magento\Catalog\Api\ProductRepositoryInterface" method="save"/>
 <resources>
 <resource ref="Magento_Catalog::products" />
 </resources>
 </route>
 <route url="/V1/products/:sku" method="PUT">
 <service class="Magento\Catalog\Api\ProductRepositoryInterface" method="save" />
 <resources>
 <resource ref="Magento_Catalog::products" />
 </resources>
 </route>
- 
 1Ok that's understandable but why would the docs say that the PUT also creates a product? I mean the sku in the path always is for identifying a product isn't it? Or can one actually create product using PUT /V1/products/:sku also?Patrik Lundgren– Patrik Lundgren2016年01月16日 10:54:43 +00:00Commented Jan 16, 2016 at 10:54
- 
 You should use Post for create and Put for update operation. Documentation is autogenerated from dockblock, this is why put and post have same descriptionKAndy– KAndy2016年01月16日 12:34:55 +00:00Commented Jan 16, 2016 at 12:34
Looking at this page: http://devdocs.magento.com/guides/m1x/api/rest/Resources/Products/products.html#RESTAPI-Resource-Products-HTTPMethod-PUT-products--id
I can see for PUT:
Description: Allows you to update an existing product.
- 
 
- 
 Sorry I should have written in the text that this was regarding Magento 2, that page is about v1.Patrik Lundgren– Patrik Lundgren2016年01月16日 10:49:59 +00:00Commented Jan 16, 2016 at 10:49
- 
 And sorry for not reading that KAndy had already pointed this out :-) I am a complete beginner when it comes to stackexchangePatrik Lundgren– Patrik Lundgren2016年01月16日 10:56:09 +00:00Commented Jan 16, 2016 at 10:56
- 
 1Well regardless of the major magento version, the rest API has the same version, doesn't it? So there is some use in pointing this out.hakre– hakre2017年02月22日 23:11:21 +00:00Commented Feb 22, 2017 at 23:11
I've got a similar problem but in my, case PUT does not work properly because:
1) FInd all products of the cart:
GET: http://my_host.dev/index.php/rest/V1/carts/8/items
( I don't know yet how to find client cartId) I found correct number by increasing the number from 1.
2) the answer was:
[ { "item_id": 11, "sku": "MH07-M-Green", "qty": 1, "name": "Hero Hoodie", "price": 54, "product_type": "configurable", "quote_id": "8", "product_option":{ "extension_attributes":{ "configurable_item_options":[{"option_id": "90", "option_value": 53 }, {"option_id": "138",...] } } } ]
2) Update cart item price by:
{ "cartItem": { "itemId": 11, "sku": "MH07-M-Green", "qty": 2, "name": "Hero Hoodie", "price": 1000, "productType": "configurable ", "quoteId": "8" } }
3) I get not Updated item price in cart (My response is the same as in point 1). I have to say also that I can delete Items from cart. Any solution for this?
Thank you