Error Codes Reference

This page provides a comprehensive reference for all error codes used in the Labels Cheap API v2. Each error code includes the HTTP status code, error message, and description.

Error Response Format

All error responses follow this consistent format:

{
    "STATUS": "error",
    "MESSAGE": "Human-readable error message",
    "CODE": "Error code (1001-5999)",
    "HTTP_STATUS": 400,
    "DATA": {},
    "TIMESTAMP": "2024-01-15 10:30:00"
}

Search & Filter

Authentication Errors (1000-1999)

Errors related to API key authentication, user permissions, and session management.

Code HTTP Status Message Description Category
1001 401 Authentication required: API key is missing The Authorization header is missing from the request AUTH
1002 401 Authentication failed: Invalid API key The provided API key is not valid or does not exist AUTH
1003 401 Authentication failed: API key is inactive The API key exists but is not currently active AUTH
1004 401 Authentication failed: API key has been revoked The API key has been permanently revoked by the system AUTH
1005 404 User not found The user account associated with the API key does not exist AUTH
1006 403 Account is inactive The user account is not currently active AUTH
1007 403 Account has been suspended The user account has been suspended due to policy violations AUTH
1008 403 Insufficient permissions for this operation The API key does not have the required permissions AUTH
1009 401 Session has expired The authentication session has expired AUTH
1010 429 Rate limit exceeded. Please try again later The request rate limit has been exceeded AUTH
1011 400 Invalid Authorization header format The Authorization header format is incorrect AUTH
1012 401 API key has expired The API key has reached its expiration date AUTH

Validation Errors (2000-2999)

Errors related to input validation, data format, and parameter requirements.

Code HTTP Status Message Description Category
2001 422 Required field is missing A required parameter is not provided in the request VALIDATION
2002 422 Invalid email format The provided email address format is invalid VALIDATION
2003 422 Invalid phone number format The provided phone number format is invalid VALIDATION
2004 422 Invalid ZIP code format The provided ZIP code format is invalid VALIDATION
2005 422 Invalid tracking number format The provided tracking number format is invalid VALIDATION
2006 422 Invalid numeric value A numeric parameter contains invalid characters VALIDATION
2007 422 String is too short A string parameter is shorter than the minimum required length VALIDATION
2008 422 String is too long A string parameter exceeds the maximum allowed length VALIDATION
2009 422 Invalid date format The provided date format is invalid VALIDATION
2010 400 Invalid JSON format The request body contains invalid JSON VALIDATION
2011 422 Invalid file type The uploaded file type is not supported VALIDATION
2012 413 File size exceeds maximum limit The uploaded file is larger than the allowed maximum VALIDATION
2013 422 Invalid carrier specified The specified shipping carrier is not supported VALIDATION
2014 422 Invalid vendor specified The specified vendor is not supported VALIDATION
2015 422 Invalid shipping service specified The specified shipping service is not available VALIDATION
2016 422 Invalid package dimensions The provided package dimensions are invalid VALIDATION
2017 422 Invalid package weight The provided package weight is invalid VALIDATION
2018 422 Invalid address format The provided address format is invalid VALIDATION
2019 422 Invalid state code The provided state code is invalid VALIDATION
2020 422 Invalid postcode format The provided postcode format is invalid VALIDATION

Business Logic Errors (3000-3999)

Errors related to business rules, account status, and operational constraints.

Code HTTP Status Message Description Category
3001 402 Insufficient balance for this operation The account does not have sufficient balance to complete the operation BUSINESS
3002 404 User account not found The user account does not exist in the system BUSINESS
3003 404 Pricing information not found Pricing information for the requested service is not available BUSINESS
3004 503 Service is currently unavailable The requested service is temporarily unavailable BUSINESS
3005 503 Vendor is currently unavailable The specified vendor is temporarily unavailable BUSINESS
3006 503 Carrier is currently unavailable The specified carrier is temporarily unavailable BUSINESS
3007 404 Tracking information not found No tracking information is available for the provided tracking number BUSINESS
3008 404 Shipment not found The specified shipment does not exist BUSINESS
3009 409 Duplicate request detected A duplicate request has been detected BUSINESS
3010 403 Operation not allowed The requested operation is not allowed for this account BUSINESS
3011 403 Account has been suspended The account has been suspended due to policy violations BUSINESS
3012 429 Daily limit exceeded The daily request limit has been exceeded BUSINESS
3013 429 Monthly limit exceeded The monthly request limit has been exceeded BUSINESS
3014 503 System is under maintenance The system is currently under maintenance BUSINESS
3015 501 Feature not available The requested feature is not available BUSINESS

System Errors (4000-4999)

Errors related to internal system operations, database, and infrastructure issues.

Code HTTP Status Message Description Category
4001 500 Database connection failed Unable to connect to the database SYSTEM
4002 500 Database query failed A database query operation failed SYSTEM
4003 500 Database transaction failed A database transaction operation failed SYSTEM
4004 500 File system operation failed A file system operation failed SYSTEM
4005 500 Memory limit exceeded The system memory limit has been exceeded SYSTEM
4006 500 Request execution timeout The request execution timed out SYSTEM
4007 500 Configuration error A system configuration error occurred SYSTEM
4008 500 Log write operation failed Unable to write to the system log SYSTEM
4009 500 Session start failed Unable to start a new session SYSTEM
4010 500 Cache operation failed A cache operation failed SYSTEM
4011 500 Encryption operation failed An encryption operation failed SYSTEM
4012 500 Decryption operation failed A decryption operation failed SYSTEM
4013 500 Email sending failed Unable to send an email SYSTEM
4014 500 SMS sending failed Unable to send an SMS SYSTEM
4015 500 PDF generation failed Unable to generate a PDF document SYSTEM
4016 500 Image processing failed An image processing operation failed SYSTEM

External API Errors (5000-5999)

Errors related to external service integrations and third-party API failures.

Code HTTP Status Message Description Category
5001 503 USPS API is currently unavailable The USPS API service is temporarily unavailable EXTERNAL
5002 502 Invalid response from USPS API The USPS API returned an invalid response EXTERNAL
5003 504 USPS API request timeout The USPS API request timed out EXTERNAL
5004 503 UPS API is currently unavailable The UPS API service is temporarily unavailable EXTERNAL
5005 502 Invalid response from UPS API The UPS API returned an invalid response EXTERNAL
5006 504 UPS API request timeout The UPS API request timed out EXTERNAL
5007 503 FedEx API is currently unavailable The FedEx API service is temporarily unavailable EXTERNAL
5008 502 Invalid response from FedEx API The FedEx API returned an invalid response EXTERNAL
5009 504 FedEx API request timeout The FedEx API request timed out EXTERNAL
5010 503 DHL API is currently unavailable The DHL API service is temporarily unavailable EXTERNAL
5011 502 Invalid response from DHL API The DHL API returned an invalid response EXTERNAL
5012 504 DHL API request timeout The DHL API request timed out EXTERNAL
5013 503 Barcode generation service is unavailable The barcode generation service is temporarily unavailable EXTERNAL
5014 502 Invalid response from barcode service The barcode service returned an invalid response EXTERNAL
5015 504 Barcode generation timeout The barcode generation request timed out EXTERNAL
5016 503 Label generation service is unavailable The label generation service is temporarily unavailable EXTERNAL
5017 502 Invalid response from label service The label service returned an invalid response EXTERNAL
5018 504 Label generation timeout The label generation request timed out EXTERNAL
5019 503 Tracking service is unavailable The tracking service is temporarily unavailable EXTERNAL
5020 502 Invalid response from tracking service The tracking service returned an invalid response EXTERNAL
5021 504 Tracking service timeout The tracking service request timed out EXTERNAL

Error Handling Best Practices

Follow these best practices when handling API errors in your applications:

1. Check Response Status

Always check the STATUS field in the response. If it's "error", handle the error appropriately.

2. Handle Different Error Categories

  • Authentication Errors (1000-1999): Prompt user to check API key or re-authenticate
  • Validation Errors (2000-2999): Display validation messages to the user
  • Business Logic Errors (3000-3999): Handle business-specific scenarios (insufficient balance, limits, etc.)
  • System Errors (4000-4999): Implement retry logic with exponential backoff
  • External API Errors (5000-5999): Implement fallback mechanisms or retry later

3. Implement Retry Logic

For transient errors (5xx status codes), implement retry logic with exponential backoff:

function retryWithBackoff(fn, maxRetries = 3) {
    return async (...args) => {
        for (let i = 0; i < maxRetries; i++) {
            try {
                return await fn(...args);
            } catch (error) {
                if (i === maxRetries - 1) throw error;
                if (error.code >= 4000 && error.code < 6000) {
                    await new Promise(resolve => 
                        setTimeout(resolve, Math.pow(2, i) * 1000)
                    );
                } else {
                    throw error;
                }
            }
        }
    };
}

4. Rate Limiting

Handle rate limiting errors (429) by implementing proper throttling:

if (response.CODE === '1010') {
    // Wait before retrying
    await new Promise(resolve => setTimeout(resolve, 60000));
    // Retry the request
}

5. Logging and Monitoring

Log error codes and messages for debugging and monitoring:

if (response.STATUS === 'error') {
    console.error(`API Error ${response.CODE}: ${response.MESSAGE}`);
    // Send to monitoring service
    logError(response.CODE, response.MESSAGE, response.TIMESTAMP);
}

Implementation Best Practices

Security

  • Never log API keys in error messages
  • Use HTTPS for all API requests
  • Validate all input data
  • Implement proper error sanitization

Performance

  • Implement connection pooling
  • Use appropriate timeouts
  • Cache responses when possible
  • Monitor API response times

User Experience

  • Display user-friendly error messages
  • Provide clear next steps for users
  • Implement graceful degradation
  • Show loading states during retries

Debugging

  • Include request IDs in error logs
  • Log full request/response context
  • Use structured logging
  • Implement error tracking