Skip to content

API requests using command line (CL) tools

There are several methods of making an HTTP request by using software tools or web services. Here we look at two CL tools - HTTPie and cURL.

HTTPie

HTTPie is a command-line HTTP client that can be used to easily access both the CKAN and DataStore endpoints. See installation instructions here.

For accessing both APIs, the command is: http the_api_endpoint.

CAKN API example

To get a list of all the themes within the CanWIN Data Catalogue, call the group_list action function by entering this command at CL:

http 'https://canwin-datahub.ad.umanitoba.ca/data/api/3/action/group_list'

DataStore API example

Here is an example of querying the DataStore for a certain resource by using the datastore_search action function:

http 'https://canwin-datahub.ad.umanitoba.ca/data/api/3/action/datastore_search?resource_id=c5c16064-e2b3-4618-9b27-0dbf5c1388c2&limit=2'

The colour-coded JSON response will look like this (using the first example):

{
    "help": "https://canwin-datahub.ad.umanitoba.ca/data/api/3/action/help_show?name=group_list",
    "result": [
        "modelling",
        "cryosphere",
        "freshwater",
        "marine",
        "remote-sensing"
    ],
    "success": true
}

This response is composed of a JSON dictionary with three keys:

  1. "help": the documentation string for the function you called, or the URL endpoint called.

  2. "result": this is the returned result from the function you called. For example, in the case of the group_list function as shown above, the result is a list of strings, which are the names of all the themes in CanWIN. If there was an error responding to your request, the dictionary will contain an "error" key with details of the error instead of the "result" key.

  3. "success": true or false


cURL

Similarly to HTTPie, an HTTP request can be made to the CKAN API using cURL at a command line interface.

For accessing both APIs, the command is: curl the_api_endpoint.

CKAN API Example

curl https://canwin-datahub.ad.umanitoba.ca/data/api/3/action/group_list

DataStore API example

curl https://canwin-datahub.ad.umanitoba.ca/data/api/3/action/datastore_search?resource_id=c5c16064-e2b3-4618-9b27-0dbf5c1388c2&limit=2

This gives the same result as HTTPie, however, the JSON output is not colour-coded or structured for easy reading.