[ckan-dev] Update Single Resource Field via API

kristi powell y2kristi at hotmail.com
Fri Feb 7 16:29:33 UTC 2014


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 Guidoin
> Director, Transportation
> Open North
> 514-862-0084
> http://opennorth.ca
> Twitter: @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/20140207/49acd523/attachment-0003.html>
-------------- next part --------------
_______________________________________________
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


More information about the ckan-dev mailing list