How to Implement a Postcode Lookup API in Your WordPress Website
A practical, step-by-step guide to adding fast, accurate UK postcode lookup to any WordPress website — using a plugin or the REST API directly.
Asking shoppers to type their full address by hand is one of the quietest conversion killers on a WordPress site. It is slow, error-prone, and the mistakes only surface later as failed deliveries and support tickets. A postcode lookup API fixes this: the customer types a UK postcode, picks their address from a clean dropdown, and the rest of the form fills itself.
This guide walks through two ways to add UK postcode lookup to WordPress — the no-code plugin route and the direct REST API route — using AutoPostcode and the official Royal Mail PAF dataset.
What you'll need
- A WordPress site (with or without WooCommerce)
- An AutoPostcode account — the free trial includes 500 lookups
- An API key for the website you're adding lookup to
Option 1: The plugin (no code)
For most WordPress sites this is the fastest path — you can be live in under five minutes.
- From your dashboard, create the website you want to enable and copy its API key.
- Install and activate the AutoPostcode plugin from your WordPress admin.
- Open the plugin settings and paste your API key.
- Choose which address fields to attach lookup to (checkout, account, or any custom form).
- Save — a "Find address" control now appears above your address fields.
Because each website uses its own scoped, revocable key, usage and billing stay isolated per site — handy if you run more than one store.
Option 2: The REST API (custom forms)
If you have a bespoke theme or custom checkout, call the lookup endpoint directly. Authenticate with your website API key and you'll get clean, structured UK addresses back as JSON.
GET /api/public/lookup?postcode=SE17PB
x-api-key: ap_live_xxxxx
[
{
"postcode": "SE1 7PB",
"line1": "London Eye",
"line2": "Riverside Building",
"town": "London",
"county": "Greater London",
"country": "United Kingdom"
}
]Wiring it into a form
Add a postcode field and a "Find address" button. On click, call the endpoint, render the results in a dropdown, and on selection map each field (line 1, line 2, town, county) to your existing inputs. Keep the manual fields available so customers can still edit if needed.
Best practices
- Always allow manual entry. Lookup should speed people up, never trap them.
- Debounce requests. Trigger on button click or after the postcode looks complete, not on every keystroke.
- Handle empty results gracefully. Show a friendly "no match — enter manually" message.
- Use one key per site. It keeps logs, usage and limits clean.
Troubleshooting
- No results: check the postcode is a valid UK format and your key matches the website.
- 401 / unauthorised: the API key is missing or wrong — re-copy it from your dashboard.
- Lookups exhausted: you've hit your plan's monthly limit; upgrade or wait for the reset.
That's it. Whether you use the plugin or the API, you'll capture cleaner customer data, reduce failed deliveries, and give shoppers a faster, friendlier checkout.
Ready to add postcode lookup to your store?
Start free with Royal Mail PAF-verified UK addresses — live on WooCommerce or WordPress in minutes.
