Search code examples
apickan

CKAN: how do I update/create the data dictionary of a resource using the api?


My company is using a CKAN instance configured with Data Store and DataPusher. When a CSV file is uploaded to CKAN, DataPusher sends it to the DataStore and creates a default Data Dictionary for the resource. The Data Dictionary is a very nice feature to display the description of data fields for the users. Here is an example (it is in Brazilian Portuguese):

Data Dictionary view in CKAN

I can update the Data Dictionary using the UI, or it can be sent as part of the Fields passed to datastore_create().

My problem, is that I don't control the call of datastore_create() because this method is automatically called buy the DataPusher service.

I want to programmatically set the values of the Data Dictionary, but I can't find the api call that allows me to do it. An api call that update the Fields metadata. Can I do it using the Api? Or maybe it is possible create it when I create the data resource. I'd like a code example.


Solution

  • You can use the API call datastore_create on top of an existing table. This will not impact the data in the table.

    You should use the datastore_search to check the format of how the dictionary is saved in one of your resources (result->fields->info). Use that as your base, make the desired changes, and use it in the body of the datastore_create call.

    Unfortunately, the API call datastore_info does not give you back that information.

    The majority of the CKAN UI functionalities can be made through the API as well. In this case, you can make use of the "datastore_create" by the controller --> See Code here.