CKAN 데이터 API

강력한 질의 지원을 하는 웹 API를 통해 리소스 데이터 접근. Further information in the main CKAN Data API and DataStore documentation.

Code examples:

Get 5 results containing "jones" in any field:
curl https://opendatanepal.com/ko_KR/api/action/datastore_search \
  -H"Authorization:$API_TOKEN" -d '
{
  "resource_id": "70bebf2f-f499-4150-9b19-1487a0c9d2eb",
  "limit": 5,
  "q": "jones"
}'
const resp = await fetch(`https://opendatanepal.com/ko_KR/api/action/datastore_search`, {
    method: 'POST',
    headers: {
        'content-type': 'application/json',
        authorization: API_TOKEN
    },
    body: JSON.stringify({
        resource_id: '70bebf2f-f499-4150-9b19-1487a0c9d2eb',
        limit: 5,
        q: 'jones'
    })
})
await resp.json()
$json = @'
{
  "resource_id": "70bebf2f-f499-4150-9b19-1487a0c9d2eb",
  "limit": 5,
  "q": "jones"
}
'@
$response = Invoke-RestMethod https://opendatanepal.com/ko_KR/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('https://opendatanepal.com/ko_KR/', apikey=API_TOKEN)
result = rc.action.datastore_search(
    resource_id="70bebf2f-f499-4150-9b19-1487a0c9d2eb",
    limit=5,
    q="jones",
)
print(result['records'])
library(httr2)

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

rc = RemoteCKAN('https://opendatanepal.com/ko_KR/', apikey=API_TOKEN)
result = rc.action.datastore_search(
    resource_id="70bebf2f-f499-4150-9b19-1487a0c9d2eb",
    filters={
      "subject": ["watershed", "survey"],
      "stage": "active",
    },
)
print(result['records'])
library(httr2)

req <- request("https://opendatanepal.com/ko_KR/api/action/datastore_search")
result <- req %>% 
    req_headers(Authorization = API_TOKEN) %>% 
    req_body_json(list(
        resource_id='70bebf2f-f499-4150-9b19-1487a0c9d2eb', 
        filters = list(
            subject = list("watershed", "survey"), 
            stage = "active")))
    req_perform %>% 
    resp_body_json
SQL query example:
curl https://opendatanepal.com/ko_KR/api/action/datastore_search_sql \
  -H"Authorization:$API_TOKEN" -d @- <<END
{
  "sql": "SELECT * FROM \"70bebf2f-f499-4150-9b19-1487a0c9d2eb\" WHERE title LIKE 'jones'"
}
END
const resp = await fetch(`https://opendatanepal.com/ko_KR/api/action/datastore_search_sql`, {
    method: 'POST',
    headers: {
        'content-type': 'application/json',
        authorization: API_TOKEN
    },
    body: JSON.stringify({
        sql: `SELECT * FROM "70bebf2f-f499-4150-9b19-1487a0c9d2eb" WHERE title LIKE 'jones'`
    })
})
await resp.json()
$json = @'
{
  "sql": "SELECT * from \"70bebf2f-f499-4150-9b19-1487a0c9d2eb\" WHERE title LIKE 'jones'"
}
'@
$response = Invoke-RestMethod https://opendatanepal.com/ko_KR/api/action/datastore_search_sql`
  -Method Post -Body $json -Headers @{"Authorization"="$API_TOKEN"}
$response.result.records
from ckanapi import RemoteCKAN

rc = RemoteCKAN('https://opendatanepal.com/ko_KR/', apikey=API_TOKEN)
result = rc.action.datastore_search_sql(
    sql="""SELECT * from "70bebf2f-f499-4150-9b19-1487a0c9d2eb" WHERE title LIKE 'jones'"""
)
print(result['records'])
library(httr2)

req <- request("https://opendatanepal.com/ko_KR/api/action/datastore_search_sql")
result <- req %>% 
    req_headers(Authorization = API_TOKEN) %>% 
    req_body_json(list(
        sql = "SELECT * FROM \"70bebf2f-f499-4150-9b19-1487a0c9d2eb\" WHERE title LIKE 'jones'"))
    req_perform %>% 
    resp_body_json

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

질의 예제 (첫 5개 결과)

https://opendatanepal.com/ko_KR/api/action/datastore_search?resource_id=70bebf2f-f499-4150-9b19-1487a0c9d2eb&limit=5

질의 예제 ('jones'을 포함하는 결과)

https://opendatanepal.com/ko_KR/api/action/datastore_search?resource_id=70bebf2f-f499-4150-9b19-1487a0c9d2eb&q=jones

질의 예제 (via SQL 문)

https://opendatanepal.com/ko_KR/api/action/datastore_search_sql?sql=SELECT * from "70bebf2f-f499-4150-9b19-1487a0c9d2eb" WHERE title LIKE 'jones'