How to access data using the API

This page is for developers and data professionals who want to access the data.gov.scot catalogue using code rather than downloading files.

What our API does

The data.gov.scot API gives you direct access to the data catalogue.

You can use it to:

  • search and filter datasets without using the website

  • get dataset metadata, such as title, description, publisher, format, licence and update frequency

  • access data for use in applications, pipelines or automated analysis

  • build integrations that update when new data is published

How our API works

The API uses CKAN, an open-source data management platform used across government.

If you have used other CKAN-based services, such as the National Data Library, the structure and query patterns on data.gov.scot may be familiar.

The metadata uses the DCAT-AP (data catalogue application profile) standard. This means it works with other open data catalogues.

APIs available on data.gov.scot

data.gov.scot has three APIs for different purposes.

Catalogue API

This allows you to find and list datasets.

You can:

  • search by keyword

  • filter by organisation or theme

  • get the full record for a dataset

Query API

This allows you to read and filter data within a dataset. Use it when you need only part of a dataset rather than the full file. For example, extracting rows of data for Glasgow from a national dataset.

Metadata API

This allows you to get structured metadata in machine-readable formats.

This is useful when integrating data.gov.scot with another catalogue or tool.

Example API requests and responses

Use the following URLs to view example API responses.

List all datasets

This returns the name of every dataset on the site.

View the API response using ‘package_list’:

https://api.data.gov.scot/api/3/action/package_list

Search for datasets

This will search for datasets using a specific term.

In this example, the search is for ‘population’. You can replace ‘population’ in the example URL with another search term.

View the API response using ‘package_search’:

https://api.data.gov.scot/api/3/action/package_search?q=population

Get a dataset’s metadata

This will return a specific dataset metadata record, including links to each of its data files.

View the API response using ‘package_show’:

https://api.data.gov.scot/api/3/action/package_show?id=labour_productivity__annual

Get an entire data file

This will return a dataset for a given resource_id. The example below will return a complete CSV file for the Labour Productivity: Annual data file.

View the API response using ‘/download’:

https://data.gov.scot/dataset/labour_productivity__annual/resource/ee33b00a-922a-4052-93ba-d8e15b65fd3b/download

Query the data file to return only what you want

This will return observations from a data file matching specific filters, in this example where 'DateCode' = 2023. Note: the filter is URL-encoded.

View the API response using ‘datastore_search’:

https://api.data.gov.scot/api/3/action/datastore_search?resource_id=ee33b00a-922a-4052-93ba-d8e15b65fd3b&filters=%7B%22DateCode%22%3A2023%7D

Get metadata in Croissant format

data.gov.scot publishes metadata using three vocabularies in a few common serialisations.

This will return metadata about the dataset and its structure in Croissant JSON-LD format.

View the API response using ‘/croissant.jsonld’:

https://admin.data.gov.scot/dataset/labour_productivity__annual/croissant.jsonld

API documentation

Read the API reference documentation on the CKAN website.

This includes information on:

  • available endpoints

  • query parameters

  • example API requests

Access requirements

You do not need to sign in or use an API key to access public datasets.

If you need help using the API

Contact the Open Data team for advice.