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

bupt bupt buptloveandroid at gmail.com
Wed May 22 05:00:36 UTC 2013


hello,
     Thank you for Adrià Mercader's reply.
     I send a post request to ckan, its address is , these information
below is the returned data.
http://127.0.0.1:5000/api/action/datastore_search?resource_id=XXXX

"
{"resource_id": "e47ce7e9-2b39-47fb-8c45-803412aae3d7", "fields": [{"type":
"int4", "id": "_id"}, {"type": "bpchar", "id": "COUNTRYCODE"}, {"type":
"bpchar", "id": "LANGUAGE"}, {"type": "bpchar", "id": "NAME"}, {"type":
"int4", "id": "SALARY"}, {"type": "numeric", "id": "LAT"}, {"type":
"numeric", "id": "LOG"}], "records": [{"SALARY": 203, "COUNTRYCODE": "am ",
"LANGUAGE": "en                            ", "LOG": "89.3", "LAT": "40.3",
"_id": 1, "NAME": "root                "}, {"SALARY": 600, "COUNTRYCODE":
"au ", "LANGUAGE": "en                            ", "LOG": "129.3", "LAT":
"20.3", "_id": 2, "NAME": "aurobot             "}, {"SALARY": 203,
"COUNTRYCODE": "ch ", "LANGUAGE": "zh                            ", "LOG":
"89.3", "LAT": "40.3", "_id": 3, "NAME": "ys                  "},
{"SALARY": 400, "COUNTRYCODE": "jp ", "LANGUAGE": "jp
     ", "LOG": "29.3", "LAT": "100.3", "_id": 4, "NAME": "jprobot
  "}, {"SALARY": 42, "COUNTRYCODE": "sp ", "LANGUAGE": "sp
           ", "LOG": "189.3", "LAT": "140.3", "_id": 5, "NAME": "robot
          "}], "_links": {"start":
"/api/action/datastore_search?resource_id=e47ce7e9-2b39-47fb-8c45-803412aae3d7",
"next":
"/api/action/datastore_search?offset=100&resource_id=e47ce7e9-2b39-47fb-8c45-803412aae3d7"},
"total": 5}
"

As you mentioned, I can use filters parameters, If I want to return only
“SALARY” data, can you tell me what is the correct address should I send
 request?
"
http://127.0.0.1:5000/api/action/datastore_search?resource_id=XXXX&filters={records:SALARY}"
to this address, Is it right?

Thank you!


2013/5/21 Adrià Mercader <adria.mercader at okfn.org>

> 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
> >
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.okfn.org/pipermail/ckan-dev/attachments/20130522/6f805f8c/attachment-0001.html>


More information about the ckan-dev mailing list