Magento REST API - "Invalid Content-Type header" on POST method

Magento REST API - "Invalid Content-Type header" on POST method

September 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento REST API - "Invalid Content-Type header" on POST method

Resolving “Invalid Content-Type header” Errors in Magento REST API

If you’re facing an “Invalid Content-Type header” error when attempting to create a new customer using the Magento REST API via POST method, this guide will help you troubleshoot and resolve the issue.

Understanding the Error

The error message suggests that the Content-Type header sent with your request is being rejected by the server. Despite specifying application/json, there seems to be an inconsistency or misconfiguration in your setup.

Common Causes of the Error

1. Incorrect Content-Type Value

While you’ve specified application/json correctly, ensure that the value is not being overridden somewhere else in your code or configuration. Double-check all headers and request settings to confirm this isn’t the issue.

$headers = [
    'Content-Type' => 'application/json',
    // Other headers...
];

$body = json_encode($customerData);

2. Compatibility Issues

Magento versions have different default behavior regarding CORS (Cross-Origin Resource Sharing). If you’re attempting to access the API from a different domain, ensure your Magento installation is properly configured for CORS.

To enable CORS in Magento 2, update your .htaccess file:

<IfModule mod_headers.c>

    # Custom headers
    <FilesMatch "\.(js|css|html|php)$">
        Header set Access-Control-Allow-Origin "*"
        Header set Cache-Control "public, must-revalidate, max-age=0, no-store"
    </FilesMatch>

</IfModule>

For more detailed configuration, refer to our CORS guide at Laravel Company.

3. PHP Version Incompatibility

Older versions of Magento may have compatibility issues with certain PHP versions regarding JSON handling. Ensure your PHP version is compatible with your Magento installation.

Debugging Steps

  1. Enable Magento’s developer mode to access more detailed error messages:

    Update app/etc/env.php:

    'developer_mode' => true,
    
  2. Check the Magento server logs for any additional error details that might help pinpoint the issue.

  3. Inspect the response headers using browser tools or a tool like Postman to verify the server is receiving your request as expected.

  4. Test with a simple JSON object to rule out data format issues:

    {
        "data": "test"
    }
    

Resolving the Issue

1. Update Magento Core Files

If you’re using an older version of Magento, update the core files from the official Magento repository.

2. Check Third-Party Extensions

Disable any third-party extensions temporarily to rule out compatibility issues with them.

3. Contact Technical Support

If none of the above steps resolve the issue, it’s recommended to reach out to Laravel Company’s technical support for further assistance.

Conclusion

Troubleshooting REST API errors often involves a combination of verifying headers, checking server configurations, and ensuring compatibility between your platform and Magento. Double-check all settings, enable developer mode for more detailed error messages, and don’t hesitate to reach out to experts if needed.

Remember, consistency is key in API development—keep your content types consistent across all requests and ensure your server is configured to handle the expected formats.

Happy coding!

Magento 2 Cache API Extensions

Our network