Reputation: 211
In my project, I used CKAN to manage my data, now I want to obtain the dataset list under my authorization(both public and private datasets), does anyone know how could I get such a list through CKAN API?
Upvotes: 1
Views: 1136
Reputation: 6392
Now @D Read's issue has been addressed, this question has a solution:
/api/3/action/package_search?include_private=True
Using HTTPie, for example:
http https://ckan.example.com/api/3/action/package_search include_private=True Authorization:123-abc
Why doesn't
/api/3/action/current_package_list_with_resources
get all resources visible to the user with the API key?! If we wanted only public resources we could omit the API key or (most logically to me) filter a search. Anyone else think this should work this way?
Thanks @D Read for the correction.
A further discovery with this endpoint - it returns a maximum of 1000 records, so if you want all results and there may be more than 1000, you need to retrieve in batches. This seems to work - self.api
is a ckanapi.RemoteCKAN
instance:
ix = 0
results = self.api.action.package_search(
include_private=True, rows=1000
)
datasets = results["results"]
while len(datasets) < results["count"]:
ix += 1000
results = self.api.action.package_search(
include_private=True, start=ix, rows=1000
)
datasets += results["results"]
That said, I don't think we ever got this endpoint to work 100% reliably.
Upvotes: 0
Reputation: 3224
Get public datasets using package_list
or package_search
.
Get datasets that your user has created, including ones that are private and drafts, using user_show
with option include_datasets=True
. Remember to use your user's api key, of course.
However I believe this leaves the private datasets created by other members of your organizations, that are not available afaict via the API. I raised an issue: https://github.com/ckan/ckan/issues/3176 in case you'd like to provide a contribute a fix or bounty for someone else to.
Upvotes: 2