HCL Commerce Version 9.1.15.0 or later

Troubleshooting: Change an API error code from 404 to 204

You can change the API response code from 404 (an error message) to 204 (an empty wish list or cart message) by updating a configuration setting.

Problem

When a call is made to a wish list or cart API and no cart or wish list is available, the API returns a 404 error message. To prevent this, the API should return a 204 response. A 204 response indicates the request was successful, but there is no content available to display.

Solution

To receive the 204 status code instead of the 404 error::
  • Open the /WC/xml/config/com.ibm.commerce.order/wc-admin-component.xml file.
  • Locate the following configuration:
    <_config:configgrouping name="ApiNotFoundToNoContentStatusCode">
    <_config:property name="cartApiNoContentStatusEnabled" value="false" />            
    <_config:property name="wishListApiNoContentStatusEnabled" value="false" />        
    </_config:configgrouping>
  • The configuration is set to false by default. To update the error code received, change the configuration values to true as shown below:
    <_config:configgrouping name="ApiNotFoundToNoContentStatusCode">            
    <_config:property name="cartApiNoContentStatusEnabled" value="true" />            
    <_config:property name="wishListApiNoContentStatusEnabled" value="true" />        
    </_config:configgrouping>
  • Restart the transaction server.
  • Call the REST APIs for the wish list and cart to verify the change:
    • store/{storeId}/wishlist/@self
    • store/{storeId}/cart/@self
Once the configuration is set to true, the system will return the 204 status code when no cart or wish list exists.