10

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?

Rafael Corrêa Gomes
13.9k15 gold badges92 silver badges190 bronze badges
asked Jan 16, 2016 at 8:01

3 Answers 3

5

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>
answered Jan 16, 2016 at 10:39
2
  • 1
    Ok 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? Commented 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 description Commented Jan 16, 2016 at 12:34
1

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.

answered Jan 16, 2016 at 10:30
4
  • It's docs for magento 1.x Commented Jan 16, 2016 at 10:35
  • Sorry I should have written in the text that this was regarding Magento 2, that page is about v1. Commented 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 stackexchange Commented Jan 16, 2016 at 10:56
  • 1
    Well 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. Commented Feb 22, 2017 at 23:11
1

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

Rafael Corrêa Gomes
13.9k15 gold badges92 silver badges190 bronze badges
answered May 20, 2016 at 10:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.