The CKAN <site>/api/3/action/package_show API provides a lot of metadata, but for tabular (row-column) resources I don't see any way to get the field names and datatypes other than by reading the resource itself and probably guessing at the datatypes. Am I missing anything?
1 Answer
If the site in question has enabled it, the CKAN's Datastore allows you to query tabular data directly via additional API functions. In your case you would probably use the datastore_info
function to get the column names and data types for a given resource.
Here's an example of getting that information for some weather data (using the excellent HTTPie command line tool):
$ http post https://transparenz.karlsruhe.de/api/3/action/datastore_info id=117ae307-902a-4bf1-9c43-8b1aa9e8c2bd
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 642
Content-Type: application/json;charset=utf-8
Date: Fri, 21 Jul 2017 11:25:19 GMT
Pragma: no-cache
Server: nginx/1.11.2
Strict-Transport-Security: max-age=31536000
Vary: X-Forwarded-Proto,X-Forwarded-Port
{
"help": "https://transparenz.karlsruhe.de/api/3/action/help_show?name=datastore_info",
"result": {
"meta": {
"count": 3550
},
"schema": {
"Apparent temperature (Degree Celcius)": "number",
"Atmospheric pressure (hPa; not normalized to sea level)": "number",
"Average wind speed (km/h; 10min window)": "number",
"Date and time (YYYY-MM-DD HH:MM:SS)": "date",
"Dew point (Degree Celcius)": "number",
"Global irradiance (W/m^2)": "number",
"Humidity (%)": "number",
"Maximum wind speed (km/h; 10min window)": "number",
"Precipitation (mm)": "number",
"Temperature (Degree Celcius)": "number",
"Wind direction (Degree)": "number"
}
},
"success": true
}
You can check whether a CKAN instance is running the Datastore
extension via the status_show
API function.