Skip to content

Using Command Line Tools to Access the CKAN API

Command-line tools let you test CKAN endpoints quickly without writing scripts.
They’re ideal for exploring datasets, checking parameters, and debugging queries.


HTTPie

HTTPie is a user‑friendly command‑line HTTP client.
It provides color‑coded, structured JSON output, making responses easier to read.

Basic usage pattern:

http <api_endpoint>
HTTPie Examples

Many core CKAN API actions accept simple GET requests. For example, to list all themes (groups):

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

Datastore actions must be called using POST, even if the URL contains query parameters. Here is an example of querying the DataStore for a certain resource by using the datastore_search action function:

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

Example JSON response (trimmed):

{
  "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
}

Note for calling the CKAN API

For HTTPie, always wrap URLs containing ? parameters in quotes:

http 'https://.../datastore_search?resource_id=...&q=fish'

But remember, for datastore actions, use POST with a JSON body instead of GET parameters.

Notes for calling DataStore actions:

  • POST must be specified explicitly.

  • JSON fields are passed as key=value pairs.

  • Numbers require := to preserve numeric type.

cURL

cURL is a widely available command‑line tool for HTTP requests.

It outputs raw JSON (no color‑coding), but is preinstalled on most systems.

Basic usage pattern:

curl <api_endpoint>
cURL Examples

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:

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

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

bash curl -X POST \ -H "Content-Type: application/json" \ -d '{"resource_id": "c5c16064-e2b3-4618-9b27-0dbf5c1388c2", "limit": 2}' \ https://canwin-datahub.ad.umanitoba.ca/data/api/3/action/datastore_search

What the cURL flags mean

Flag Meaning
-X POST Sets the HTTP method to POST (required for datastore actions).
-H "Content-Type: application/json" Adds an HTTP header; tells CKAN the request body is JSON.
-d '{...}' Sends the JSON payload containing parameters like resource_id, limit, or filters.

HTTPie vs cURL

Tool Pros Cons
HTTPie Pretty JSON, simpler syntax Requires installation
cURL Preinstalled on most systems Raw, less readable

Authentication

Some API functions require an API key.

Include it in your request using the Authorization header:

http POST https://canwin-datahub.ad.umanitoba.ca/data/api/3/action/package_list \ "Authorization:YOUR-API-KEY"
curl -H "Authorization: YOUR-API-KEY" \
https://canwin-datahub.ad.umanitoba.ca/data/api/3/action/package_list