[ckan-dev] Update Single Resource Field via API

kristi powell y2kristi at hotmail.com
Sat Feb 8 12:52:53 UTC 2014


Thank you for the help!

Date: Fri, 7 Feb 2014 11:44:25 -0500
From: stephane at opennorth.ca
To: ckan-dev at lists.okfn.org
Subject: Re: [ckan-dev] Update Single Resource Field via API

How are you trying to do it? Directly in command line? Or using a script?
In any case, if you are directly targetting the resource you want, there is no need to have the "resource" parent item.

On top of that, if you want to update an existing resource, you need the id, so it should be at least {"id": "c06bcbd6-18d7-42bb-9fc4-e0263d8c5a19", "name":"test"}



On Fri, Feb 7, 2014 at 11:29 AM, kristi powell <y2kristi at hotmail.com> wrote:

responded to the wrong thread...

im trying to do it through the API as a PUT request I get a 404 as a POST I get a 409 error. 

should my message body look like this as an example:

{"resource":{"name":"test"}}
thanks. 


On Feb 7, 2014, at 9:39 AM, "Stéphane Guidoin" <stephane at opennorth.ca> wrote:


Hello,
Interestingly, I faced the same issue few minutes ago.
The "update" in CKAN works as the HTTP verb PUT: what you provide will completely erase all the fields. So in my case, I was changing this groups, but I lost my resources because the resource structure was missing in my package data dict.


It's a bit of trouble, bit if would make things easier if CKAN could have an additional action to do the same as PATCH (https://tools.ietf.org/html/rfc5789), which only updates the fields provided.


In any case, if you do it via a script, it is not that difficult to do (here is an example with ckanapi for a package where I "merge" the existing dictionnary with the new value I have created:


        package_exists, current_package = self.package_exist(package["name"])        if package_exists:

            self.logger.info("Package exists - put it - %s" % package["name"])


            #If a field is not provide in the new package, we keep the old value            current_package.update(new_package_entity)

            self.ckanapi.action.package_update(**current_package)        else:            self.logger.info("Package does not exist - post it - %s" % package["name"])

            self.ckanapi.action.package_create(**new_package_entity)               



On Fri, Feb 7, 2014 at 3:15 AM, Nigel Babu <nigel.babu at okfn.org> wrote:


Hello Kristi,

Can you try doing a resource_show, modifying the dict, and then pushing it back via resource_update?




Nigel Babu




Developer  |  @nigelbabu



The Open Knowledge Foundation



Empowering through Open Knowledge



http://okfn.org/  |  @okfn  |  OKF on Facebook  |  Blog  |  Newsletter












CKAN | http://ckan.org/ | @CKANproject | the world’s leading open-source data portal platform






On 7 February 2014 10:16, kristi powell <y2kristi at hotmail.com> wrote:






Hello...
I am trying to update a single field at the resource level via the API.  I'm using the update_resource method.  In the body I have a json object for example: "{"key":"value"}" but it's returning an error "Conflict."




How can I change the value of just the single field without rewriting the entire resource?
Thanks,
Kristi 		 	   		  

_______________________________________________

ckan-dev mailing list

ckan-dev at lists.okfn.org

https://lists.okfn.org/mailman/listinfo/ckan-dev

Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev





_______________________________________________

ckan-dev mailing list

ckan-dev at lists.okfn.org

https://lists.okfn.org/mailman/listinfo/ckan-dev

Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev




-- 
Stéphane GuidoinDirector, Transportation
Open North
514-862-0084

http://opennorth.caTwitter: @opennorth / @hoedic

_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org

https://lists.okfn.org/mailman/listinfo/ckan-dev
Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev


_______________________________________________

ckan-dev mailing list

ckan-dev at lists.okfn.org

https://lists.okfn.org/mailman/listinfo/ckan-dev

Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev




-- 
Stéphane GuidoinDirector, Transportation
Open North
514-862-0084
http://opennorth.caTwitter: @opennorth / @hoedic


_______________________________________________
ckan-dev mailing list
ckan-dev at lists.okfn.org
https://lists.okfn.org/mailman/listinfo/ckan-dev
Unsubscribe: https://lists.okfn.org/mailman/options/ckan-dev 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20140208/ab546c8a/attachment-0003.html>


More information about the ckan-dev mailing list