Error Response Format
When an API request fails, OpenCart returns a JSON response with anerror object containing detailed error information.
Standard Error Response
Example Error Response
Error Types
Validation Errors
Validation Errors
Errors related to input validation, including length checks, format validation, and required fields.
Product Errors
Product Errors
Errors related to product availability, stock, and options.
Cart Errors
Cart Errors
Errors related to cart operations and stock validation.
Address Errors
Address Errors
Errors related to address validation.
Order Errors
Order Errors
Errors during order confirmation and processing.
Common Error Messages
Customer & Authentication Errors
| Error Message | Cause | Solution |
|---|---|---|
Customer data required | Customer not set in session | Call customer API to set customer data |
Customer group not found | Invalid customer group ID | Use valid customer group ID |
Customer does not exist | Invalid customer ID | Verify customer exists in database |
Product & Cart Errors
| Error Message | Cause | Solution |
|---|---|---|
Product does not exist | Invalid product ID | Verify product ID is correct |
Product is out of stock | Insufficient stock quantity | Check product quantity availability |
Minimum order quantity is X | Below minimum quantity | Increase quantity to meet minimum |
Product option is required | Missing required option | Provide all required product options |
Product option is not valid | Invalid option value | Use valid option IDs and values |
Address Errors
| Error Message | Cause | Solution |
|---|---|---|
First name must be between 1 and 32 characters | Invalid firstname length | Provide valid firstname |
Address must be between 3 and 128 characters | Invalid address length | Provide complete address |
Please select a country | Missing or invalid country | Provide valid country_id |
Please select a region / state | Missing zone for country | Provide valid zone_id |
Postcode must be between 2 and 10 characters | Invalid postcode | Provide valid postcode |
Order Errors
| Error Message | Cause | Solution |
|---|---|---|
Cart is empty | No products in cart | Add products before checkout |
Payment address is required | Missing payment address | Set payment address |
Shipping address is required | Missing shipping address | Set shipping address |
Shipping method is required | No shipping method selected | Select shipping method |
Payment method is required | No payment method selected | Select payment method |
Validation Functions
OpenCart uses these validation functions:Length Validation
Email Validation
Regex Validation
Error Handling Best Practices
Check for Errors
Always check if the response contains an
error key before processing data.Display Field Errors
Show field-specific errors next to the relevant input fields for better UX.
Log API Errors
Log error responses for debugging and monitoring API issues.
Retry Logic
Implement retry logic for transient errors with exponential backoff.
Example Error Handling
PHP Example
JavaScript Example
HTTP Status Codes
OpenCart API typically returns HTTP 200 status code for all responses. Error detection should be based on the presence of the
error key in the JSON response, not HTTP status codes.Debugging Tips
- Enable Error Logging - Check OpenCart error logs for detailed error information
- Validate Input Data - Ensure all required fields are provided with correct data types
- Check Session State - Verify session contains required data before operations
- Test Incrementally - Test each API call individually before chaining operations
- Review Source Code - Check controller validation logic for specific requirements
Next Steps
Authentication
Learn about API authentication
Cart API
Explore cart operations
Orders API
Learn order management
Products API
Access product information

