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?

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>
|improve this answer|||||
  • 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? – Patrik Lundgren Jan 16 '16 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 – KAndy Jan 16 '16 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.

|improve this answer|||||
  • It's docs for magento 1.x – KAndy Jan 16 '16 at 10:35
  • Sorry I should have written in the text that this was regarding Magento 2, that page is about v1. – Patrik Lundgren Jan 16 '16 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 – Patrik Lundgren Jan 16 '16 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. – hakre Feb 22 '17 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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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