magento2: Updating customers through rest/V1/customers/:id fails since 2.2.2
Preconditions
- We first tested this on version 2.2.1 – updating customers through the API works.
- We then upgraded to version 2.2.2 – updating customers through the API fails.
The error persists in 2.2.3.
Steps to reproduce
- Create a customer through the API.
- Update a customer through the API.
We use Python to interface with Magento.
Our update call is:
requests.put('{}/rest/V1/customers/{}'.format(
api.endpoint, customer_id), headers=api.headers,
json=customer)
The customer-value passed onto the json argument is:
{'customer': {'store_id': 1, 'website_id': 1, 'group_id': 1, 'firstname': 'Anonymous', 'lastname': 'Anonymous', 'email': 'valid@email.org', 'taxvat': None, 'addresses': [{'firstname': 'Anonymous', 'lastname': 'Anonymous', 'telephone': '0123456789', 'company': 'Anonymous Inc.', 'street': ['Where the streets have no name 1'], 'postcode': '1000AA', 'city': 'Amsterdam', 'country_id': 'NL', 'default_billing': False, 'default_shipping': False}, {'firstname': 'Anonymous', 'lastname': 'Anonymous', 'telephone': '0123456789', 'company': 'Anonymous BV', 'street': ['Where the streets have no name 1'], 'postcode': '1000AA', 'city': 'Amsterdam', 'country_id': 'NL', 'default_billing': False, 'default_shipping': False}], 'custom_attributes': [{'attribute_code': 'external_reference', 'value': 10011}]}}
I have made some adjustments to the above to filter out sensitive data. Hopefully I didn’t mess up the json data itself but our import worked on Magento 2.2.1.
Expected result
JSON including the updated customer.
Actual result
{'message': 'A customer with the same email already exists in an associated website.', 'trace': etc.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 18 (8 by maintainers)
Hello @ju5t, thank you for your report. We’ve acknowledged the issue and added to our backlog.
@orlangur, this bug introduced in https://github.com/magento/magento2/commit/0379ec65e08e2fb6e02739bc6149ecc4e6ab970b , by changing param name “:id” to “:customerId”. https://github.com/magento/magento2/blob/7621060f9c750de44f2229fcad837f57d62d780a/app/code/Magento/Customer/etc/webapi.xml#L131-L136
https://github.com/magento/magento2/blob/50f974b0c8f3ada8d7a2c9b0f9924976dacd2088/app/code/Magento/Customer/etc/webapi.xml#L131-L136
but, in CustomerInterface field entity id is “id”, not “customerId”. Therefore Webapi/Controller/Rest/ParamsOverrider cannot convert customerId param into body field id, so customer object has no “id” in CutomerRepositoy::save() and CustomerRepository tries to create new customer instead of update existing one.
Using the swagger interface we get the same issue. We cannot update a single attribute for a customer using the customer/customerId endpoint. We must pass in the customer ID as well as email, name and first name. This defeats the purpose of passing in the customer ID to the endpoint.
Hi @ju5t .
Unfortunately, we are not able to reproduce this issue on fresh 2.4-develop. Seems like this issue was already fixed in #28332.
Manual testing scenario:
Actual Result: ✔️ The customer was successfully updated
So, we have to close it. Please feel free to comment, reopen or create new ticket according to the Issue reporting guidelines if you are still facing this issue on the latest
2.4-developbranch. Thank you for collaboration.Hi @engcom-Alfa could you confirm that issue isn’t reproducing anymore and we can close this PR?
@ihor-sviziev, sorry, I can’t. As said we do not use Magento anymore.
@magento-engcom-team please explain why you have choose to ignore and close a PR?
Everybody is spending a lot of time on this (debugging, raising an issue, providing a solution) and you just drop the ball.
We have dropped Magento from our stack. I am still happy that we did. Changes like this to an API without documentation are unacceptable.
https://github.com/magento/magento2/pull/21236