-
Notifications
You must be signed in to change notification settings - Fork 36
ATI API HowTo
get your API key from the “My Account | My Profile” page on the left-hand side. The API key is a UUID like “fd179b44-...-6c3649d056d1”. Please do not put that key in any code you share with other people. Use something like a config file or environment variable and let each user input their own key when they use your tool. That key is equivalent to your password and could be used to do anything your user account can do on the Registry. All actions with that key will be logged as actions you performed.
The CKAN API uses a JSON-RPC style, where you post a JSON object and receive another JSON object in response. Your API key is passed in the “Authorization” header.
Resource IDs include:
- "eddf3b18-5dec-4eaa-a2e5-c95df52bdeab" for the Transport Canada ATI summaries
- "bd12f58e-ad20-466f-8bac-a0365de77352" for Transport Canada ATI nothing to report
For a complete list of resource IDs for ati-summaries we can query the API and use the "jq" tool to format the output:
curl http://registry.statcan.gc.ca/api/action/package_search \
-d '{"q": "type:ati-summaries", "rows": 500}' \
| jq '.result[][] | {org_title:.organization.title, resource_id:.resources[0].id}'
Replace "ati-summaries" with "ati-none" above for the nothing-to-report resource IDs
You can request the current records with “datastore_search”: http://docs.ckan.org/en/latest/maintaining/datastore.html#ckanext.datastore.logic.action.datastore_search
To get the 10 latest ATI records with curl from the command line:
curl http://registry.statcan.gc.ca/api/action/datastore_search \
-H"Authorization:${API_KEY}" -d @- <<JSON
{
"resource_id": "eddf3b18-5dec-4eaa-a2e5-c95df52bdeab",
"limit": 10,
"sort": "year desc, month desc"
}
JSON
One of the records looks like:
{
"disposition": "Disclosed in part / Communication partielle",
"summary_fra": "Copies des rapports de vérification et d’évaluation du système de gestion de la sécurité des chemins de fer réglementés par le gouvernement fédéral du 1er janvier 2011 à aujourd’hui (10 septembre 2013).",
"month": 10,
"request_number": "A-2013-00516",
"summary_eng": "Copies of the Safety Management System Audit and Evaluation Reports of federally regulated railways, between January 1, 2011 to present (September 10, 2013).",
"year": 2014,
"_id": 2731,
"pages": 779
}
The “_id” field is generated internally, but all other fields should be provided when posting ATI summaries to “datastore_upsert”
The API you need to use is the CKAN Datastore “datastore_upsert” command: http://docs.ckan.org/en/latest/maintaining/datastore.html#ckanext.datastore.logic.action.datastore_upsert
e.g. using curl to publish one record:
curl http://registry.statcan.gc.ca/api/action/datastore_upsert \
-H"Authorization:${API_KEY}" -d @- <<JSON
{
"resource_id": "eddf3b18-5dec-4eaa-a2e5-c95df52bdeab",
"records":[
{
"disposition": "Disclosed in part / Communication partielle",
"summary_fra": "Tous les documents",
"month": 3,
"request_number": "A-2015-00999",
"summary_eng": "All records about everything",
"year": 2015,
"pages": 9
}
]
}
JSON
“datastore_upsert” will automatically replace records with the same request number.
ATI nothing to report records are similar but have only “year” and “month” fields.
First verify that the record you would like to remove is present with “datastore_search”
e.g:
curl http://registry.statcan.gc.ca/api/action/datastore_search \
-H"Authorization:${API_KEY}" -d @- <<JSON
{
"resource_id": "eddf3b18-5dec-4eaa-a2e5-c95df52bdeab",
"filters": {
"request_number": "A-2015-00999"
}
}
JSON
Then remove that record with the same parameter by using “datastore_delete” instead of “datastore_search”.
Nothing to report records are removed by providing the year and month, e.g. with datastore_search:
curl http://registry.statcan.gc.ca/api/action/datastore_search \
-H"Authorization:${API_KEY}" -d @- <<JSON
{
"resource_id": "bd12f58e-ad20-466f-8bac-a0365de77352",
"filters": {
"year": 2015,
"month": 3
}
}
JSON