boars
boars

Reputation: 361

Obtain a dataset id/name of a resource in CKAN via a single API call?

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.

Upvotes: 4

Views: 4089

Answers (1)

Ross
Ross

Reputation: 406

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"

Upvotes: 8

Related Questions