Developers
Look Up a UPCS Code with the API
Call GET /v1/upcs/lookup/{code} to get coordinates, address, country and share link for a UPCS code, and handle the 404 for unknown codes.
Updated 14 October 2026 · 2 min read
A lookup turns a code such as PK-1A2B-3C4D back into a location. Use it to verify codes entered by customers and to fetch coordinates for routing or display.
Request
curl https://api.upcs.io/api/v1/upcs/lookup/PK-1A2B-3C4D \
-H "x-api-key: $UPCS_API_KEY"
Response
The JSON contains upcs_code, a location object, a maps object with map links, and share_url. Inside location you will find latitude, longitude, address, label, country_code and country_flag.
async function lookup(code) {
const res = await fetch(
'https://api.upcs.io/api/v1/upcs/lookup/' + encodeURIComponent(code),
{ headers: { 'x-api-key': process.env.UPCS_API_KEY } }
);
if (res.status === 404 || res.status === 400) return null; // unknown or malformed code
const data = await res.json();
if (!res.ok) throw new Error(data.code || data.message || data.error);
return data;
}
Using it for validation
A regular expression can reject obviously malformed input, but only a lookup confirms the code is real. The pattern below is a loose check for the CC-XXXX-XXXX format and is no substitute for the API call; see storing a UPCS code in your database.
const looksLikeUpcs = /^[A-Za-z]{2}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}$/;
Normalise case before comparing or storing, for example uppercasing, and trim whitespace.
Common patterns
- On order submission, look up the entered code, store the returned coordinates, and show the address back to the customer for confirmation.
- Cache successful lookups, because a code always refers to the same cell; see caching strategies.
- If you receive
429, use backoff.
Keep your key on the server and expose a small endpoint of your own to the browser. See securing your UPCS API key.
Frequently asked questions
What happens with a code that does not exist?
The endpoint returns a 404 for a well-formed code that does not exist, and a 400 for a malformed one. Treat both as an invalid code and ask the customer to check it.
Should I encode the code in the URL?
Yes. Passing it through your HTTP library's URL encoding is a safe habit, even though codes use letters, digits and hyphens.
