Skip to content
Clear Postcode

Integration · Code

UK postcode lookup in JavaScript

One fetch call returns everything about a UK postcode. Use a secret key on your server (Node.js) and a domain-locked publishable key in the browser.

Get a free key10,000 lookups a month free · no card

Set it up

  1. 1Get a free key at /developers.
  2. 2Server: put the secret key in an environment variable. Browser: use a publishable key with your domain listed.
  3. 3Call the endpoint and read data.

The code

const r = await fetch("https://api.clearpostcode.co.uk/v1/postcodes/" + encodeURIComponent("sw1a 1aa"), {
  headers: { "x-api-key": process.env.CLEAR_KEY },
});
if (r.status === 404) throw new Error("Postcode not found");
const { data } = await r.json();
console.log(data.postcode, data.local_authority.name, data.location.latitude, data.location.longitude);

Questions

JavaScript and Node.js questions

Is there an npm package?

fetch is all you need today; every response is plain JSON with an OpenAPI 3.1 description for typed clients.