Errors — Geocodes API
Tell an unknown postal code apart from a real match, and handle the few errors Geocodes returns.
The Geocodes API is public — no token, no Authorization header. It is designed to be called from a checkout page directly.
It almost never returns an error. A lookup that finds nothing looks like a lookup that worked, so check what comes back.
It does not tell you when it found nothing
API reference → Location by postal code
A lookup that matches nothing answers 200 with an empty array. Not 404, not an error object. An unknown postal code, a country that does not exist and plain garbage all look identical to a successful call:
GET /zipcode/MX/64000 → 200 [ { "zip_code": "64000", … } ]
GET /zipcode/MX/00000 → 200 []
GET /zipcode/ZZ/64000 → 200 []
GET /zipcode/MX/abc → 200 []Check the array's length. The status code tells you nothing about whether the address exists.
const res = await fetch(`https://geocodes.envia.com/zipcode/${country}/${zip}`);
const rows = await res.json(); // always an array
if (rows.length === 0) {
// Not an outage. The postal code does not exist, or we have no data for it.
// Ask the buyer to check it — do not fall through to quoting.
}Responses are raw arrays
Unlike the Management API, there is no data wrapper. The response is the array. Code that reads body.data gets undefined and usually fails a step later, far from the cause.
The one error you can actually get
{ "statusCode": 400, "error": "Bad Request", "message": "Invalid request params input" }It comes from the country code, which must be exactly two characters. MEX fails; MX works. It is the only validation on these operations, so in practice a 400 here always means the same thing.
There is no 401 — there is nothing to authenticate. And no 429: this API is not rate limited the way the Management API is.
Why the empty array matters more than it looks
An empty result is your earliest warning that a shipment will fail, and it arrives before the buyer has paid you anything.
If Geocodes has no data for a destination, the carriers that depend on coverage tables will quote fewer options or none at all — and if a label does get created, it is the kind that comes back. Validating at checkout costs one public call. Finding out later costs the return trip.
Validate the postal code when the buyer types it, not when you create the label.
Related pages
- Geocodes API overview — what the service is for
- Return to Sender — what an address error costs once the parcel is moving
- Errors (Management API) — a different service, a different error shape
Next steps
Look up postal codes, cities and coordinates. One host, no token.
Read a Shipping API error, know what its code means, and decide what to do next.
What an address needs in each country, where each value comes from, and five rules that apply everywhere.
Updated 18 days ago