Skip to main content
Evolution API uses standard HTTP status codes and consistent error response formats to communicate issues. Understanding these error patterns will help you build robust integrations.

HTTP Status Codes

Evolution API implements the following HTTP status codes (src/api/routes/index.router.ts:28-36):
All error responses include a consistent JSON structure for easy parsing and error handling.

Error Response Format

Evolution API error responses follow this standard format:
number
required
The HTTP status code (400, 401, 403, 404, or 500)
string
required
A human-readable error name matching the HTTP status
string | array
required
Detailed error description. Can be a string or array of error messages

Error Types and Exceptions

Evolution API defines custom exception classes in src/exceptions/:

400 Bad Request

Implementation: src/exceptions/400.exception.ts Thrown when the request contains invalid parameters, missing required fields, or fails validation.
Common Causes:
  • Missing required fields in request body
  • Invalid data types (string instead of number)
  • JSONSchema validation failures
  • Malformed JSON in request body
  • Invalid phone number formats
  • File upload errors
Example Scenarios:
Request:
Response (400):
Request:
Response (400):
Request:
Response (400):
The validation logic is in src/api/abstract/abstract.router.ts:96-144.

401 Unauthorized

Implementation: src/exceptions/401.exception.ts Thrown when authentication is missing or invalid.
Common Causes:
  • Missing apikey header
  • Invalid global API key
  • Invalid instance token
  • Using instance token for another instance
  • Expired or revoked credentials
Example Scenarios:
Request:
Response (401):
Validated in src/api/guards/auth.guard.ts:15-17.
Request:
Response (401):
The key is validated against both the global key and instance tokens in src/api/guards/auth.guard.ts:19-50.
Request:
Response (401):

403 Forbidden

Implementation: src/exceptions/403.exception.ts Thrown when authentication is valid but the operation is not permitted.
Common Causes:
  • Using instance token to create instances (requires global key)
  • Attempting to access protected administrative endpoints
  • IP address not in metrics allowlist
  • Invalid metrics authentication
Example Scenarios:
Request:
Response (403):
Instance creation requires the global API key (src/api/guards/auth.guard.ts:23-25).
Request:
Response (403):
IP validation is in src/api/routes/index.router.ts:48-63.
Request:
Response (403):
Path traversal protection is in src/api/routes/index.router.ts:169-183.

404 Not Found

Implementation: src/exceptions/404.exception.ts Thrown when the requested resource does not exist.
Common Causes:
  • Instance name does not exist
  • Chat or message ID not found
  • Group JID does not exist
  • Contact not in WhatsApp database
  • File or media not found
Example Scenarios:
Request:
Response (404):
Request:
Response (404):
Request:
Response (404):
File existence check is in src/api/routes/index.router.ts:185-190.

500 Internal Server Error

Implementation: src/exceptions/500.exception.ts Thrown when the server encounters an unexpected error.
Common Causes:
  • Database connection failures
  • WhatsApp connection errors
  • Unhandled exceptions in business logic
  • External service timeouts
  • File system errors
  • Memory or resource exhaustion
Example Scenarios:
Response (500):
Database errors are logged and caught by the error handling middleware.
Response (500):
Request:
Response (500):
Returned when metrics auth is required but not configured (src/api/routes/index.router.ts:71-73).

Validation Errors

Evolution API uses JSONSchema7 for request validation (src/api/abstract/abstract.router.ts:46-60). Validation errors return detailed information:

Single Validation Error

Multiple Validation Errors

Schema Description Override

If the JSONSchema includes a description field, it’s used as the error message:
Error Response:

Error Handling Best Practices

Client-Side Error Handling

Implement comprehensive error handling in your client code:

Retry Logic for 500 Errors

Implement exponential backoff for transient server errors:

Logging and Monitoring

Log errors for debugging and monitoring:

Troubleshooting Common Errors

”Unauthorized” on Valid Requests

Symptoms:
  • Receiving 401 errors despite using correct API key
  • Authentication works in some environments but not others
Solutions:
  1. Check header name: Ensure you’re using apikey (lowercase)
  2. Verify no extra whitespace: Trim API keys before sending
  3. Check instance exists: Verify the instance name is correct
  4. Database check: Ensure instance token matches database record

”Bad Request” with Unclear Messages

Symptoms:
  • Receiving 400 errors with generic validation messages
  • Not sure which field is causing the error
Solutions:
  1. Enable debug logging: Check server logs for detailed validation errors
  2. Test with minimal payload: Start with required fields only
  3. Validate JSON syntax: Use a JSON validator to ensure proper formatting
  4. Check data types: Ensure strings are quoted, numbers are not

”Instance not found” Immediately After Creation

Symptoms:
  • Instance creation succeeds (201 response)
  • Immediate subsequent requests return 404
Solutions:
  1. Check instance name: Ensure you’re using the exact name from creation
  2. Wait for initialization: Add a small delay after creation
  3. Check database: Verify instance was persisted

”Internal Server Error” on Message Send

Symptoms:
  • Message endpoint returns 500 error
  • Other endpoints work fine
Solutions:
  1. Check instance connection: Ensure instance is connected to WhatsApp
  2. Verify phone number format: Use international format without ’+’
  3. Check server logs: Look for specific error messages
  4. Test WhatsApp connection: Try reconnecting the instance

Error Logging

Evolution API logs errors using the Logger service (src/config/logger.config.ts):
Configure log levels:
Error logs include timestamps, context, and stack traces for debugging. Monitor logs in production to identify patterns and fix issues proactively.

Next Steps

Authentication

Learn about API authentication and tokens

API Overview

Return to API overview

Instance Management

Create and manage instances

Send Messages

Start sending WhatsApp messages