Skip to main content

Migrate from the core clients

@ideal-postcodes/core-node, @ideal-postcodes/core-axios, @ideal-postcodes/core-browser and @ideal-postcodes/core-interface are deprecated. They receive no new features. Use @ideal-postcodes/sdk instead. It runs on native fetch in browsers and Node.js 22 or later, with no runtime dependencies.

If you use Address Finder or Postcode Lookup, you need do nothing. The widgets manage their own API client.

npm uninstall @ideal-postcodes/core-axios
npm install @ideal-postcodes/sdk

Look up a postcode​

before.tsts
import { Client, lookupPostcode } from "@ideal-postcodes/core-axios";

const client = new Client({ api_key: "ak_test" });
const addresses = await lookupPostcode({ client, postcode: "BR8 7RE" });
after.tsts
import { createIdpcClient, lookupPostcode } from "@ideal-postcodes/sdk";

const client = createIdpcClient({ apiKey: "ak_test" });
const { addresses } = await lookupPostcode({ client, postcode: "BR8 7RE" });

Like the core version, the SDK's lookupPostcode returns empty addresses for an unknown postcode instead of throwing, with the closest postcodes in suggestions. The lower-level postcodes throws an ApiError with code 4040. See error handling.

Function mapping​

core clients@ideal-postcodes/sdk
new Client({ api_key })createIdpcClient({ apiKey })
lookupPostcode({ client, postcode })lookupPostcode({ client, postcode }), then addresses
lookupAddress({ client, query })addresses({ client, query: { query } }), then data.result.hits
autocomplete.list / autocomplete.resolvefindAddress / resolveAddress, or createAutocomplete
checkKeyUsability / keys.retrievekeyAvailability({ client, path: { key } })
IdpcRequestFailedError and other error classesApiError, with status, code and message

createIdpcClient also takes baseUrl, fetch, headers and timeoutMs. Pass throwOnError: false to an operation to get { data, error } instead of a rejection.

Every operation has its own reference page.