CKAN-API
“CKAN is the leading software solution which can be used to develop Open Data portals. CKAN supports administration by centralising Open Data activities. Cataloguing, versioning, storage and recording published data.”
Prerequisites for using the API
- You should know how JSON should be read.
- You should understand the basic principles of REST APIs.
- You have an API key from the Developer Dashboard.
Way to find the latest version of a resource
We will use ‘timetable-2016-hrdf’ (periodic timetable) as an example. Using the ‘package_list’ request (see below), you can also look up the other possible datasets (e.g. ‘bhlist’).
You must skip steps 3 and 4 because the resource IDs change during harvesting. Each resource always has a unique resource ID.
Procedure:
- Use the CKAN API
- Find the dataset slug (in this case ‘timetable-2016-hrdf’) or perform a general lookup with https://api.opentransportdata.swiss/ckan-api/package_list
- Export the dataset’s content https://api.opentransportdata.swiss/ckan-api/package_show?id=timetable-2016-hrdf
- Search within the resources. The latest Periodic Timetable must be uploaded. How recent it is can be determined by the date (YYYY-MM-DD) in the “url” field.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
{ "license_title":"Andere (Offen)", "resources":[ //…Other ressource { "byte_size":13851261, "coverage":"Coverage", // lot of attributes "title":"{\"fr\": \"Periodic timetable 2016 (HDRF)\", \"de\": \"Periodic timetable 2016 (HDRF)\", \"en\": \"Periodic timetable 2016 (HDRF)\", \"it\": \"Periodic timetable 2016 (HDRF)\"}", // lots of attributes "url":"https://opentransportdata.swiss/dataset/9f0babdc-0bdb-4400-b6fa-fd6d1f11cd5d/resource/e521f5d9-7f42-446f-9746-29ba2c26dfd8/download/fp20162016-09-24.zip", // lots of things // } |
- Please note that the next periodic timetable is always ready from around November (the annual timetable is already earlier). Other datasets such as Didok remain and are independent of the timetable year.
- The URL (‘url’) enables you to download the file
Some important facts to know
The CKAN API is not designed for extremely intensive activity. This means that you do not use CKAN API as a datawarehouse, but for local requests and for automatically identifying resources for downloading.
Other metadata
Via https://api.opentransportdata.swiss/ckan-api/package_show?id=timetable-2016-hrdf you will also see all the other relevant metadata in the data.
In Element resources the relevant details are listed for a single resource.
Access to individual data elements
How to access individual fields is described using the Didok pseudo services .