Question

I have uploaded some data to the CKAN datastore. I want to create, update or delete a row/column to the data in the datastore?

How to do that in CKAN using Datastore API?

Était-ce utile?

La solution

See the Datastore API docs, specifically, I think datastore_upsert and datastore_delete are what you want.

Autres conseils

You can achieve your requirement by CKAN Datastore API's

Example :

For Create, update and delete you have to need CKAN API KEY which you can get from your profile page of CKAN. You have to pass this API KEY through headers Authorization : {{YOUR_CKAN_API_KEY}}

Create a Datastore

For creating a datastore you have to POST the parameter to your endPoint.

Endpoint : http://{{YOUR_CKAN_DOMAIN}}/api/3/action/datastore_create

Post Values :

{ "resource": {
        "package_id": "{{Package_ID}}"

    }, 
  "fields": [ 
           {"id" : "id"},
             {"id": "name"},
              {"id": "age"}

            ],
  "primary_key":["id"],

  "records": [  { "id":"1","name": "Alex", "age": "25"},
            {"id":"2", "name": "Rony", "age": "12"},
            { "id":"3","name": "Julis", "age": "20"}
             ]

}

Primary Key is an optional parameter . If you need to update a unique/primary key is needed. You can also specify the type of each field in fields parameter.

Datastore Upsert (update or insert)

Endpoint : http://{{YOUR_CKAN_DOMAIN}}/api/3/action/datastore_upsert

POST Values:

{ 
  "resource_id": "{{resource_id}}", 
  "force":true, 
  "records": [ 
                { "id":"3","name": "David", "age": "18"},
            {"id":"4", "name": "John", "age": "22"}

             ],
  "method" : "insert"


}

Possible methods: upsert/insert/update. By default the value is upsert (Update if record with same key already exists, otherwise insert. Requires unique key.)

For Delete

Endpoint : http://{{YOUR_CKAN_DOMAIN}}/api/3/action/datastore_delete

POST Values:

{ 
  "resource_id": "{{resource_id}}", ", 
  "force":true, 
  "filters": {
        "name" : "Alex"
      }

}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top