Skip to content

ATI API HowTo

Ian Ward edited this page Mar 25, 2015 · 10 revisions

Yes, step 1 is to 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 is 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.

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

Your Resource IDs are:

  • "eddf3b18-5dec-4eaa-a2e5-c95df52bdeab" for the Transport Canada ATI summaries
  • "bd12f58e-ad20-466f-8bac-a0365de77352" for Transport Canada ATI nothing to report

You can request the current records with “datastore_search”: http://docs.ckan.org/en/latest/maintaining/datastore.html#ckanext.datastore.logic.action.datastore_search

For example, to get the 10 latest ATI records with curl from the command line:

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”, e.g. using curl:

  • curl http://registry.statcan.gc.ca/api/action/datastore_upsert -H'Authorization:$API_KEY' -d'{"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}]}'

“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.

Be very careful with the “datastore_delete” command. Calling it without a filter will delete all the records from the table. Please test your filter condition with “datastore_search” before calling “datastore_delete”

Clone this wiki locally