Track timeseries by CDID
Fetch UK inflation, unemployment, GDP, and other economic indicators by CDID — including how to discover CDIDs, structure timeseries data, and parse values correctly.
CDIDs are the fastest and most reliable way to access ONS indicator data. If you're building a dashboard that displays UK economic indicators, this is the primary path you'll use.
What is a CDID?
A CDID (Coded Data IDentifier) is a four-character alphanumeric code that uniquely identifies a single statistical series across the entire ONS publication catalogue. Think of it like a ticker symbol: L55O always means CPIH annual rate, regardless of what page or dataset it appears in.
CDIDs are stable. ONS does not reassign them when tables are restructured or methodologies are updated, which makes them safe to hardcode in application config.
Key CDIDs for common indicators:
| CDID | Indicator |
|---|---|
L55O | CPIH (Consumer Prices Index incl. housing costs) annual rate |
CZBH | CPI (Consumer Prices Index) annual rate |
MGSX | UK unemployment rate (16+, seasonally adjusted) |
DYDC | UK employment rate (16-64) |
ABMI | UK GDP (expenditure, chained volume measures, £ billions) |
KGX7 | UK trade balance (goods and services) |
LF24 | UK average weekly earnings (total pay, 3-month average) |
Fetching by CDID
getTimeseriesByCdid is the simplest entry point. It searches for the CDID, retrieves the full data URI, and fetches the complete timeseries — all in one call. Pass one CDID or an array; it always returns an array of DataResponse objects in the same order.
The DataResponse structure
Each response contains three arrays of datapoints — choose the granularity that matches your use case:
value is always a string. ONS returns numeric values as strings (e.g. "3.4"). Always call parseFloat(dp.value) before doing arithmetic. Datapoints where the value is not available may carry "" or a non-numeric string — guard with Number.isFinite() after parsing.
Choosing the right granularity
Most ONS economic indicators are published monthly. For CPI, unemployment, and earnings, .months will be the populated array. For GDP, .quarters is typically more complete. Annual summaries live in .years.
Lower-level: getData(uri)
If you already have the ONS URI for a timeseries — from a search result, from your own config, or from a previous getTopicContent call — you can call getData directly and skip the search step.
This is marginally faster than getTimeseriesByCdid since it skips the search call. Use it when you're building a pipeline where URIs are stored from a prior discovery step.
Discovering CDIDs by keyword
If you don't know the CDID for an indicator, use search to find it:
The search result's cdid field gives you the CDID directly. The uri field can be passed to getData if you want to skip a second search.
You can also narrow by topic or dataset:
Handling the nextRelease field
description.nextRelease is a plain-text string as ONS publishes it — not a machine-parseable ISO date. Common formats include "14 May 2025" and "May 2025". Use it for display; don't rely on it for programmatic scheduling without parsing.
If you need to check whether new data is available, compare the updateDate on the most recent datapoint against a stored value.
Complete example: CPIH vs CPI spread dashboard
Fetch the last 24 months of CPIH and CPI monthly data, calculate the spread (CPIH includes owner-occupiers' housing costs, CPI does not), and format for display.
Getting the latest reading only
If you only need the current value and not the full history, slice .at(-1) from the appropriate array:
ONS sometimes publishes data with a short lag between the release announcement and the API reflecting the new figures. If your application needs to surface data the moment it's published, poll on the release date and compare updateDate on the latest datapoint against the previous known value.