Closed Antimated closed 2 years ago
This is expected behaviour. Craft and Commerce 4 have changed how JSON responses are handled, so rather than returning a success
key you need to check the status code of the response to determine whether the request was a success (status is 200
) or not (status is 400
). There's a discussion on the change here and I believe it was mentioned in the release notes, though I can't find that at the moment. It's covered in the upgrade guide for plugins, which is where I was made aware of the change, but unfortunately it's not mentioned in the front-end upgrade guides for Craft or Commerce, which I feel is a bit of an oversight.
The Commerce 4.x docs for controller JSON responses are out of date and show the old JSON response, but the Craft 4.x docs for controller JSON responses are correct.
Thanks for jumping in here @martyspain !
@Antimated I have made an issue over on the docs repo to make some updates/fixes to the docs so this is more clear to people upgrading from a previous version of Commerce.
Thanks!
What happened?
Description
Doing a post request to the
cart/update-cart
controller with the headersAccept: application/json
doesn't return the succes/error (and probably more) keys as the docs describe.In commerce 3 the following data was returned for a successful update-cart response (notice the success key being present):
This is how it looks in commerce 4: Success (no success key):
Error (no error key):
Not sure if this a bug or if the docs are inaccurate (or perhaps an mistake on my part)
Steps to reproduce
cart/update-cart
with 'Accept: application/json' headersExpected behavior
Response should include a success, error and/or error key.
Actual behavior
Screenshot of post request done with Axios
Craft CMS version
Craft Pro 4.2.0.2
Craft Commerce version
4.1.0
PHP version
8.1.5
Operating system and version
Darwin 20.5.0
Database type and version
MySQL 5.7.34
Image driver and version
GD 8.1.5
Installed plugins and versions