Magento – Update Customer data with REST API

customermagento2rest api

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.

Best Answer

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

Related Topic