1

SO I am not sure if this is a bug or not, when using the API to update a product in magento 2.3.0 a PUT request like such:

curl -X PUT "https://example.com/index.php/rest/all/V1/products/24-MB01" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN" -d "{ \"product\": { \"visibility\": 3 }}"

updates the visibility for the product with that SKU (as one would expect) however when i try to make a simillar update to a customer with a PUT request like this:

curl -X PUT "https://example.com/index.php/rest/all/V1/customers/8" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN" -d "{ \"customer\": { \"middlename\": \"string\" }}"

I get a 400 error with "message": "The customer email is missing. Enter and try again." the API to update only works if i add all of the required data like this:

curl -X PUT "https://example.com/index.php/rest/all/V1/customers/8" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer TOKEN" -d "{ \"customer\": { \"id\": \"8\", \"firstname\": \"Jon\", \"lastname\": \"Smith\", \"email\": \"Jjsmith@gmail.com\", \"middlename\": \"jac\", \"store_id\": 1, \"website_id\": 1 }}"

if I leave any of these values out i get an error with the exception of id which if left out creates a new record or throws an error if the email already exists (despite the id being specified at the end of the URL) also when id is passed in with the data that IDs record is updated even if it is not the id at the end of the URL

This does not seem to be the way the API should operate any help or explanation of whats going on would be appreciated.

1

I created an issue and a PR for thiswill see if magento accepts it...

https://github.com/magento/magento2/pull/21236

https://github.com/magento/magento2/issues/21237

0

"/V1/customers/:customerId" PUT is used for updating.

"/V1/customers" POST for creating.

You always have to provide the full-customer object

  • 1
    My question is why do you need to provide the full customer object? why doesn't the ID in the URL suffice as it does for the product, also what is the point of the ID in the URL as it is ignored and the one in the object is used regardless of which ID is in the URL – Yehuda Schwartz Jan 22 '19 at 15:01
  • 1
    ask magento-core-developers ;-) – Philipp Sander Jan 22 '19 at 15:03
  • What is the proper channel to ask them? – Yehuda Schwartz Jan 22 '19 at 15:06
  • 1
    i'd recommend slack – Philipp Sander Jan 22 '19 at 15:07
  • 1
    @YehudaSchwartz some entities are updated using replace strategy (like Customer), while the others - using patch strategy (like Products). There is inconsistency in this area mostly due to historical reasons: lack of standardization and parallel development by independent teams. – Alex Paliarush Jan 22 '19 at 18:00

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.