Guidance

for users, publishers and sysadmins

API

The data.gov.uk API is provided by CKAN and extensions.

The CKAN API docs are extensive: http://ckan.readthedocs.org/en/release-v2.2.3/

All the action functions return help text detailing parameters etc.

Below are some tips relating to data.gov.uk

Datasets

If you want to process lots or all the dataset metadata, rather than making tens of thousands of requests, please just download our daily dump in JSON or CSV format: Datasets JSON Datasets CSV

A list of datasets: https://data.gov.uk/api/action/package_list

Details of a dataset: https://data.gov.uk/api/action/package_show?id=cabinet-office-energy-use

Searching

Search on the API is very similar to the data.gov.uk search page. Guidance for Finding Data also applies to this API.

The parameters to package_search are passed through to SOLR, so consult the SOLR docs for more info.

Free text - the q parameter works like the data.gov.uk search box and looks for the specified works in title, description etc.. By default, the best matches are returned first. It uses stemming, so ‘fish’ also returns results containing ‘fishes’, ‘fishing’ etc.

e.g. https://data.gov.uk/api/action/package_search?q=fish

By field - use the fq parameter to filter on particular fields. Returns exact matches. It uses roughly the same syntax as in the URL of the web search.

e.g. Publisher: https://data.gov.uk/api/action/package_search?fq=publisher:peterborough-city-council

Further examples are at: Finding Data.

NB Remember to escape these URLs. Most browsers will escape these automatically when you click on these example links, but python clients etc. will mostly need them URL encoded (spaces to %20 etc). And on the command-line remember to quote the whole URL e.g. use single quotes:

curl 'https://data.gov.uk/api/action/package_search?fq=res_url:"http://opendatacommunities.org/sparql"'

Organization hierarchy

data.gov.uk uses CKAN organizations to store what is shown as “publisher”s on the front-end.

A list of the organizations: https://data.gov.uk/api/action/organization_list

Details of one organization: https://data.gov.uk/api/action/organization_show?id=cabinet-office&include_datasets=false

You can also get the whole organization tree: https://data.gov.uk/api/action/group_tree?type=organization

And the tree below a particular top-level organization: https://data.gov.uk/api/action/group_tree_section?type=organization&id=department-for-business-innovation-and-skills