6

I'm looking to search Data.gov and using the CKAN API for this. as a start I want to do a simple text search like this one for environmental data. some questions related to this:

  1. It appears that every API response includes a JSON piece with help information. can this be excluded?
  2. The response does not appear to include information on the total number of hits. how can API clients get information on this total number of hits of searches?
  3. Does the CKAN API support spatial selection criteria as seems to be implemented at data.gov? it appears the catalog.data.gov UI does do some form of spatial filtering (within/overlap is unclear), but the API returns an error when using the ext_bbox parameter: "Search Query is invalid: "Invalid search parameters: ['ext_bbox']""
  • 1
    This would be better to ask as three questions. – fgregg Aug 27 '13 at 16:21
  • I am not seeing the error. Perhaps it was a bug? – Dan Temkin Jan 8 '18 at 22:06
8

You've asked three separate questions in one question, I don't think this fits into Stack Exchange's one question, one answer model, should have been three separate posts maybe. But anyway..

It appears that every API response includes a JSON piece with help information. can this be excluded?

No :) Not as far as I know. Just ignore it. I agree it seems a little unnecessary.

The response does not appear to include information on the total number of hits. how can API clients get information on this total number of hits of searches?

The package_search link you posted does actually contain the number of hits, that's the "count": 8511 bit.

Does the CKAN API support spatial selection criteria as seems to be implemented at data.gov? it appears the catalog.data.gov UI does do some form of spatial filtering (within/overlap is unclear), but the API returns an error when using the ext_bbox parameter: "Search Query is invalid: "Invalid search parameters: ['ext_bbox']""

The CKAN version that catalog.data.gov is using does not support ext_bbox parameters on GET requests, but later CKAN versions do:

http://demo.ckan.org/api/3/action/package_search?q=test&ext_bbox=-180,-90,180,90

On catalog.data.gov you need to send a POST request as in the following example:

curl -X POST -d '{"q":"environmental", "extras": {"ext_bbox": "-130,30,-50,40"}}' http://catalog.data.gov/api/3/action/package_search
0

1) As mentioned by @sean-hammond you would have to do the exclusion on the client side. Although it does contain the total number of results:

..."success": true, "result": {"count": 3395, "sort": "views_recent_desc",...

Also the help could be useful if you needed an error resolution or help function in your application.

2) From the structure above the total results appear to be available.

json["help"]["result"]["count"]

3) I clicked the link above you said was causing an error and it returned a valid json. Maybe it was a glitch? Try again and let me know if you are still having problems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.