Error Response Formats
Error response formats for the Shipping, Queries, and Geocodes APIs — with real examples and a helper to normalize all three.
Each Envia API has its own error response shape. This page documents the real formats returned by the Shipping, Queries, and Geocodes APIs so you can handle them correctly in your integration.
Error response formats
Each Envia API returns errors in its own format. Your error-handling code should account for these differences.
Shipping API
The Shipping API wraps errors inside a meta / error object:
{
"meta": "error",
"error": {
"code": 400,
"description": "Invalid Option",
"message": "The origin.postalCode field is required."
}
}| Field | Type | Description |
|---|---|---|
meta | string | "error" for error responses |
error.code | int | Numeric error code |
error.description | string | Short error category (e.g., "Invalid Option") |
error.message | string | Human-readable detail of the issue |
Important: Some Shipping API errors return HTTP
200with"meta": "error"in the body instead of a 4xx status code. Always check themetafield in the response — do not rely solely on the HTTP status code.
Authentication errors on the Shipping API return a plain-text string instead of JSON:
"Authentication error."
Handle this case in your code by checking the Content-Type header or wrapping JSON parsing in a try/catch.
Queries API
The Queries API uses a different structure:
{
"statusCode": 401,
"error": "Unauthorized",
"message": "Invalid or expired token."
}| Field | Type | Description |
|---|---|---|
statusCode | int | HTTP status code |
error | string | Error name (e.g., "Unauthorized", "Not Found") |
message | string | Human-readable description of the issue |
Geocodes API
The Geocodes API follows the same structure as the Queries API:
{
"statusCode": 404,
"error": "Not Found",
"message": "Postal code not found for the given country."
}Handling all three formats
Since each API has its own error shape, a robust integration should normalize errors into a common internal format. Here is a simple approach:
function parseEnviaError(response, body) {
// Shipping API — plain-text auth error
if (typeof body === "string") {
return { code: response.status, message: body };
}
// Shipping API — meta/error wrapper
if (body.meta === "error") {
return { code: body.error?.code, message: body.error?.message };
}
// Queries & Geocodes API
if (body.statusCode) {
return { code: body.statusCode, message: body.message };
}
return { code: response.status, message: "Unknown error" };
}Tip: Some carrier-level errors include an additional
carrier_messagefield with the carrier's own error text — useful when debugging carrier-specific rejections.
Getting help
If an error persists after checking the response format:
- Capture the full JSON error response including
carrier_messageif present - Note the endpoint URL, HTTP method, and timestamp
- Open a support ticket with these details
What to read next:
- Webhooks Guide — Webhook error handling and delivery troubleshooting
- Production Readiness Checklist — Error handling checklist items
- Core Workflow — See error handling in context of the full shipping flow
Updated 1 day ago
