[ckan-dev] Getting resources from packages via the ckanapi

Timothy Giles timothy.giles at slu.se
Thu Feb 23 19:21:15 UTC 2017


Hi Andrew,

Once you have the package id, you can :


                 packageObj = ckan.action.package_show('id:' package['id'])



This will return you the package object with all the resources included. You can loop through the resources if you want but I believe all the resource metadata is provided.



Regards Tim


From: ckan-dev [mailto:ckan-dev-bounces at lists.okfn.org] On Behalf Of Koebrick, Andrew (MNIT)
Sent: den 23 februari 2017 19:44
To: ckan-dev at lists.okfn.org
Subject: [ckan-dev] Getting resources from packages via the ckanapi

Hoping somebody can assist:  I am attempting to create a report for one of my ckan instances that lists all the organizations, and then all of their packages along with the id of the packages' resource (we have only one resource per package).  However, I do not seem to be able to link to the resource id via API calls.

Here is what I have so far:

organizations = ckan.action.organization_list(include_datasets ='True')
for organization in organizations:

         packages= orgDetails['packages']

         for package in packages:

                 #And here is where it breaks down.... Here are a few of the many searches / shows I have tried:

                 resourceObj = ckan.action.resource_search(query='package_id:' +package['id'])

                    #which returns: {u'query': u'Field "package_id" not recognised in resource_search.', u'__type': u'Validation Error'}

                 revisionObj = ckan.action.revision_show(id=package['revision_id'])

                    #which just brings back information already knows about the revision.





While iterating through the package information I seem unable to get the related resources.  I have tried all sorts of queries using what info I have from the package to get the related resources.



What can I use to link from the package list found in the return object from organization_show to get resources?



Many thanks,

Andrew Koebrick  |  MINNESOTA GEOSPATIAL INFORMATION OFFICE
Web Coordinator / Systems administrator / Librarian
MN.IT Services @ MNGEO
651-201-2465 (w)  |   651-296-6398 (f) |  andrew.koebrick at state.mn.us<mailto:andrew.koebrick at state.mn.us>
658 Cedar St., Room 300, St. Paul, MN 55155, www.mngeo.state.mn.us<http://www.mngeo.state.mn.us/>

[cid:image002.jpg at 01CE61F8.52552AE0]<http://www.mn.gov/oet>

Information Technology for Minnesota Government   |   mn.gov/mnit<http://www.mn.gov/oet>



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20170223/6d133c38/attachment-0003.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 1624 bytes
Desc: image001.jpg
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20170223/6d133c38/attachment-0003.jpg>


More information about the ckan-dev mailing list