Costa Rica postal code API endpoints

All of them answer GET with JSON from https://api.postalcr.dev. An unknown code returns 404. Codes are always strings: "10305", never 10305.

See the endpointsView on GitHub

13
endpoints
494
districts
6,891
towns and beaches

The 7 provinces

The province list, or one province with its cantons. A province code is one digit, 1 to 7.

  • /provincias.jsonThe 7 provinces, with area and number of cantons and districts
  • /provincias/{provincia}.jsonOne province (1–7) and its cantons
GET /provincias/1.json

{
  "codigo": "1",
  "nombre": "San José",
  "area_km2": 4969.8,
  "cantones": [
    { "codigo": "101", "nombre": "San José", "distritos": 11, "url": "…" },
    { "codigo": "102", "nombre": "Escazú", "distritos": 3, "url": "…" },
    …
  ],
  "distritos": 123,
  "url": "https://postalcr.dev/san-jose/"
}

The 84 cantons

A canton code is 3 digits: the province plus the canton number. Desamparados is 103.

  • /cantones.jsonAll 84 cantons with their province
  • /cantones/{canton}.jsonOne canton and its districts
GET /cantones/103.json

{
  "codigo": "103",
  "nombre": "Desamparados",
  "provincia": { "codigo": "1", "nombre": "San José" },
  "area_km2": 118.9,
  "distritos": [
    { "codigo_postal": "10301", "nombre": "Desamparados", "gam": true, "url": "…" },
    …
  ],
  "url": "https://postalcr.dev/san-jose/desamparados/"
}

The 494 districts

Each district is one postal code. The full list carries every field; the code route returns one.

  • /distritos.jsonAll 494 districts (277 KB, 57 KB gzipped)
  • /distritos/{codigoPostal}.jsonOne district by its postal code
codigo_postal
The 5 digits: province, canton and district
nombre
The district name, as the IGN writes it
canton · provincia
{ codigo, nombre } objects
etiqueta
Ready to display: district, canton, province
area_km2
Area in km²
gam
true when inside the Greater Metropolitan Area
centro
[lat, lon] of a point inside the district
vecinos
Codes of the districts that share a boundary
pueblos
Towns and beaches inside the district
url
Its page on postalcr.dev
GET /distritos/10203.json

{
  "codigo_postal": "10203",
  "nombre": "San Rafael",
  "canton": { "codigo": "102", "nombre": "Escazú" },
  "provincia": { "codigo": "1", "nombre": "San José" },
  "etiqueta": "San Rafael, Escazú, San José",
  "area_km2": 13.0,
  "gam": true,
  "centro": [lat, lon],
  "vecinos": ["10107", "10108", "10109", "10201", …],
  "pueblos": ["San Rafael"],
  "url": "https://postalcr.dev/san-jose/escazu/san-rafael/"
}

6,891 towns and beaches

Official places that are not districts: towns, hamlets, district seats, indigenous territories and beaches, each with its district’s postal code.

Names repeat (there are 54 San Rafael): identify a place by nombre and codigo_postal, never by the name alone. categoria is Playa, Cabecera de distrito, Poblado, Caserío or Territorio/Comunidad indígena.

GET /pueblos.json

[
  {
    "nombre": "Santa Teresa",
    "tipo": "pueblo",
    "categoria": "Poblado",
    "alias": [],
    "codigo_postal": "60111",
    "distrito": "Cóbano",
    "canton": "Puntarenas",
    "provincia": "Puntarenas",
    "coordenadas": [lat, lon],
    "url": "https://postalcr.dev/lugares/santa-teresa-cobano/"
  },
  …
]

Boundaries of the 494 districts

A FeatureCollection with one MultiPolygon per district, simplified from the IGN 1:5,000 boundaries. Neighboring districts share exactly the same edge.

GET /distritos.geojson

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "codigo_postal": "10101",
        "nombre": "Carmen",
        "etiqueta": "Carmen, San José, San José",
        "gam": true,
        "url": "https://postalcr.dev/san-jose/san-jose/carmen/"
      },
      "geometry": { "type": "MultiPolygon", "coordinates": [ … ] }
    },
    …
  ]
}

Codes inside and outside the GAM

Two lists of postal codes: 167 inside the Greater Metropolitan Area and 327 outside, with the definition and criterion used.

  • /gam.jsondefinicion, criterio, fuente, gam and no_gam

See the GAM list

GET /gam.json

{
  "definicion": "Gran Área Metropolitana según el Plan GAM 2013-2030 (Decreto Ejecutivo 38334, MIVAH).",
  "criterio": "Un distrito es GAM si está pintado como distrito de la GAM en el mapa oficial. …",
  "fuente": { "mapa": "…", "url": "…", "distritos": "…" },
  "gam": ["10101", "10102", "10103", …],
  "no_gam": ["10504", "10505", …]
}

Version 2.0.0, metadata and spec

Every response carries open CORS (Access-Control-Allow-Origin: *) and is cached for an hour in the browser and a day on Cloudflare’s network.

GET /meta.json

{
  "version": "2.0.0",
  "edicion_dta": "2026",
  "totales": {
    "provincias": 7,
    "cantones": 84,
    "distritos": 494,
    "distritos_gam": 167,
    "pueblos": 6891
  },
  "fuentes": [ … ],
  "documentacion": "…",
  "repositorio": "…"
}