Fetch time series data
Retrieve historical data by vector or by table coordinate, handle scalar factors, and batch multiple series in a single call.
The WDS API offers several methods for fetching time series data depending on how you want to address a series and what time range you need. This guide walks through the main patterns for building dashboards, running analyses, or feeding data pipelines.
Addressing modes: vectorId vs productId + coordinate
Every series in the WDS has two stable identifiers:
vectorId — A numeric ID prefixed with v in StatCan's publications (e.g. v41690973). This is the simplest and most reliable way to retrieve a specific series. Vector IDs do not change when StatCan revises table structure or re-releases data.
productId + coordinate — The table ID (productId, e.g. 18100004) combined with a dot-separated coordinate string (e.g. '1.1.0.0.0.0.0.0.0.0'). Each position in the coordinate corresponds to a dimension in the table, and the value is the member code within that dimension. This is useful when you're navigating a table programmatically and constructing the series address from dimension selections.
For most use cases, prefer vectorId. Use the coordinate approach when you need to enumerate or select across dimensions.
Get the last N periods
getDataFromVectorsAndLatestNPeriods is the most common method. It returns the latestN most recently published datapoints for each requested vector.
The equivalent using productId + coordinate:
Get data for a date range
getDataFromVectorByReferencePeriodRange returns all datapoints whose reference period falls within the given range. Reference periods are the period the data describes (e.g. '2024-01' for January 2024), not the release date.
You can also pass an array of vector IDs to fetch multiple series over the same range:
Working with datapoints: values, scale, and precision
Each datapoint in vectorDataPoint has the following structure:
Applying the scalar factor — The value field is stored at the scaled unit. To get the actual number, multiply by 10 raised to the power of scalarFactorCode:
For example, if value = 158.1 and scalarFactorCode = 0, the actual value is 158.1 (CPI index, units). If value = 20123.4 and scalarFactorCode = 3, the actual value is 20,123,400 (thousands).
Null values — value can be null when data is suppressed, not yet available, or revised to not applicable. Always handle nulls before arithmetic.
Display precision — Use decimals only for formatting output. It describes how many decimal places StatCan rounds to in their publications.
Batch multiple series in one call
Methods that accept arrays send all requests in a single HTTP call and return results in the same order:
There is no hard limit documented for batch size, but large batches may time out. In practice, batches of up to 100 vectors work reliably. For very large requests, split into chunks of 50–100.
Look up series metadata
Before fetching data, you may want to confirm what a vector contains — its title, frequency, and scale. Use getSeriesInfoFromVector:
SeriesTitleEn gives you a plain-language description like "Consumer Price Index (CPI), all-items, Canada". This is useful for labelling charts or validating that a vector ID points to what you expect.
Full example: CPI chart data
Bulk data by release date
If you need all data released within a specific date-time window (rather than by reference period), use getBulkVectorDataByRange. This is suited for reconciliation jobs where you want to capture all revisions published between two timestamps:
Note that the vector IDs here are passed as strings with the v prefix, and the date-time format is 'YYYY-MM-DDTHH:mm'.