When agencies provide their data files in an open and machine readable format (CSV for example), data.govt.nz can make this data available via its "DataStore API". The Datastore API is a useful tool for you to query specific rows of data within a data resource. It allows you to query and consume the same data in JSON format. Each row in the datastore corresponds to a Primary Key, identified by the _id field.
API Endpoints
Simple DataStore query endpoint: https://catalogue.data.govt.nz/api/action/datastore_search
SQL DataStore endpoint: https://catalogue.data.govt.nz/api/action/datastore_search_sql
DataStore API Documentation
Available at http://docs.ckan.org/en/2.7/maintaining/datastore.html#the-datastore-api
Example: Using searching a resource
- Identify the data resource you want and retrieve it's ID, for instance:
4c5f6967-6c6d-4981-aa10-6b6790918cb5
. - Create the URL call:
https://catalogue.data.govt.nz/api/action/datastore_search?q=health&resource_id=4c5f6967-6c6d-4981-aa10-6b6790918cb5
. - Make a web request to the above URL and you will receive a response. After parsing the JSON response into an object, check if the request was successful by ensuring that the response-json-object.success value evaluates to true before proceeding.
- Query parameter q can be either a string or a dictionary. If it is a string, it will search on all fields on each row. If it is a dictionary as {"key1": "a", "key2": "b"}, it will search on each specific field.