CKAN Data API

Access resource data via a web API with powerful query support. Further information in the main CKAN Data API and DataStore documentation.

Code examples:

Get 5 results containing "jones" in any field:
curl http://5.189.187.109/lt/api/action/datastore_search \
  -H"Authorization:$API_TOKEN" -d '
{
  "resource_id": "589b9f5c-8428-457d-b4e7-9b0f8075b995",
  "limit": 5,
  "q": "jones"
}'
const resp = await fetch(`http://5.189.187.109/lt/api/action/datastore_search`, {
    method: 'POST',
    headers: {
        'content-type': 'application/json',
        authorization: API_TOKEN
    },
    body: JSON.stringify({
        resource_id: '589b9f5c-8428-457d-b4e7-9b0f8075b995',
        limit: 5,
        q: 'jones'
    })
})
await resp.json()
$json = @'
{
  "resource_id": "589b9f5c-8428-457d-b4e7-9b0f8075b995",
  "limit": 5,
  "q": "jones"
}
'@
$response = Invoke-RestMethod http://5.189.187.109/lt/api/action/datastore_search`
  -Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"}
$response.result.records

(using the ckanapi client library)

from ckanapi import RemoteCKAN

rc = RemoteCKAN('http://5.189.187.109/lt/', apikey=API_TOKEN)
result = rc.action.datastore_search(
    resource_id="589b9f5c-8428-457d-b4e7-9b0f8075b995",
    limit=5,
    q="jones",
)
print(result['records'])
library(httr2)

req <- request("http://5.189.187.109/lt/api/action/datastore_search")
result <- req %>% 
    req_headers(Authorization = API_TOKEN) %>% 
    req_body_json(list(
        resource_id = '589b9f5c-8428-457d-b4e7-9b0f8075b995',
        limit = 5,
        q = 'jones'))
    req_perform %>% 
    resp_body_json
Get results with either "watershed" or "survey" as subject and "active" as its stage:
curl http://5.189.187.109/lt/api/action/datastore_search \
-H"Authorization:$API_TOKEN" -d '
{
"resource_id": "589b9f5c-8428-457d-b4e7-9b0f8075b995",
  "filters": {
    "subject": ["watershed", "survey"],
    "stage": "active"
  }
}'
const resp = await fetch(`http://5.189.187.109/lt/api/action/datastore_search`, {
    method: 'POST',
    headers: {
        'content-type': 'application/json',
        authorization: API_TOKEN
    },
    body: JSON.stringify({resource_id: '589b9f5c-8428-457d-b4e7-9b0f8075b995', filters: {
        subject: ['watershed', 'survey'],
        stage: 'active'
    }})})
await resp.json()
$json = @'
{
  "resource_id": "589b9f5c-8428-457d-b4e7-9b0f8075b995",
  "filters": {
    "subject": ["watershed", "survey"],
    "stage": "active"
  }
}
'@
$response = Invoke-RestMethod http://5.189.187.109/lt/api/action/datastore_search`
  -Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"}
$response.result.records
from ckanapi import RemoteCKAN

rc = RemoteCKAN('http://5.189.187.109/lt/', apikey=API_TOKEN)
result = rc.action.datastore_search(
    resource_id="589b9f5c-8428-457d-b4e7-9b0f8075b995",
    filters={
      "subject": ["watershed", "survey"],
      "stage": "active",
    },
)
print(result['records'])
library(httr2)

req <- request("http://5.189.187.109/lt/api/action/datastore_search")
result <- req %>% 
    req_headers(Authorization = API_TOKEN) %>% 
    req_body_json(list(
        resource_id='589b9f5c-8428-457d-b4e7-9b0f8075b995', 
        filters = list(
            subject = list("watershed", "survey"), 
            stage = "active")))
    req_perform %>% 
    resp_body_json

Some API endpoints may be accessed using a GET query string.

Query example (first 5 results)

http://5.189.187.109/lt/api/action/datastore_search?resource_id=589b9f5c-8428-457d-b4e7-9b0f8075b995&limit=5

Query example (results containing 'jones')

http://5.189.187.109/lt/api/action/datastore_search?resource_id=589b9f5c-8428-457d-b4e7-9b0f8075b995&q=jones