4

Please note the URLS contained in the post aren't real - just examples

Is it possible to check what dataset/s a resource sits in via a single api query?

It seems possible to do via a 3 step query such as:

  1. Get revision ID: http://demo.ckan.org/api/3/action/resource_search?query=url:https://www.example.com/resources/datafile.csv
  2. Get package ID: http://demo.ckan.org/api/3/action/revision_show?id=de5707gg-5568-1291-83df-7a6e2a441396
  3. Get containing dataset: http://demo.ckan.org/api/3/action/package_show?id=de5707gg-5568-1291-83df-7a6e2a441396

Alternatively I've been able to use: https://demo.ckan.org/api/action/package_search This allows me to get all packages and info contained within then use javascript on a page to process the results, this gives me the dataset/s if any are applicable.

However I'm curious if this can be done in a single API call as opposed to doing multiple or having to rely on something outside of CKAN to process (ie without using Javascript as in second example).

I thought it might have been possible to do something like: https://data.qld.gov.au/api/action/package_search?q=de5707gg-5568-1291-83df-7a6e2a441396 but it does not seem to search ID fields? I'd prefer to search by URL as I wouldn't necessarily know what the ID is to begin with unfortunately and the package search doesn't have this content to search across.

boars
  • 351
  • 4
  • 8

1 Answers1

8

To search for the ID field, you can pass it to package_show in the fq parameter like:

https://data.gov.uk/api/3/action/package_search?q=&fq=id:e3939ef8-30c7-4ca8-9c7c-ad9475cc9b2f

Similarly you can find packages that have a specific resource URL with (note the ")

https://data.qld.gov.au/api/3/action/package_search?fq=res_url:"https://www.dnrm.qld.gov.au/__data/assets/excel_doc/0005/282533/dnrm-gifts-and-benefits-june-2015.xlsx"

Ross
  • 406
  • 2
  • 4
  • 1
    Thank you Ross, your answer is good and even makes use of the CKAN instance we use. haha! Another query if I may? Is there a logic to the fq=res_url pattern? Or a list of them, for instance group_name etc. grp_name (for the group name) – boars Oct 07 '15 at 00:29
  • 2
    You want to see https://github.com/ckan/ckan/blob/master/ckan/config/solr/schema.xml#L80-L153 - this really could do with being documented better though. – Ross Oct 07 '15 at 15:16