[ckan-dev] how to create REST api like "/api/action/datastore_search?business=waterfee&cityid=TJ"

Adrià Mercader adria.mercader at okfn.org
Tue May 21 10:43:46 UTC 2013


You can filter results in the datastore_search, using the the filters
parameter [1], eg:

{"business": "waterfee", "cityid": "TJ"}

Note that you will need to use a POST request for the time being, as
there is a bug that prevents the filters parameter from working on GET
requests [2]

Alternatively you can use the datastore_search_sql [3] endpoint and
define a SQL statement. Should be something like:

http://127.0.0.1/api/action/datastore_search_sql?resourceid=XXX&sql=SELECT
* FROM XXX WHERE business = 'waterfee' AND cityid = 'TJ'


Adrià

[1] http://docs.ckan.org/en/latest/datastore-api.html#ckanext.datastore.logic.action.datastore_search
[2] https://github.com/okfn/ckan/pull/917
[3] http://docs.ckan.org/en/latest/datastore-api.html#ckanext.datastore.logic.action.datastore_search_sql

On 20 May 2013 03:13, bupt bupt <buptloveandroid at gmail.com> wrote:
> hello everyone,
>         I want to create REST api like
> "http://127.0.0.1/api/action/datastore_search?business=waterfee&cityid=TJ",
> and only return TJ city's waterfee data which is JSON format. Now the CKAN
> platform only create REST API like
> ""http://127.0.0.1/api/action/datastore_search?resourceid=XXX" and return
> all the data of dataset. It is not smart because I only want it to return TJ
> city's waterfee data.
>      Could you tell me how to achieve this goal. where and which file should
> I modify to realize this function. Do I need to create new files?
>      thank you very much!
>
> _______________________________________________
> ckan-dev mailing list
> ckan-dev at lists.okfn.org
> http://lists.okfn.org/mailman/listinfo/ckan-dev
> Unsubscribe: http://lists.okfn.org/mailman/options/ckan-dev
>




More information about the ckan-dev mailing list