Skip to content

Commit

Permalink
Updated how to filter and specify fields on datastore api. (#2912)
Browse files Browse the repository at this point in the history
* Updated how to filter and specify fields on datastore api.

* Added examples in code blocks.
  • Loading branch information
dharizza authored and janette committed Jun 27, 2019
1 parent 84fa647 commit 03f1b86
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion docs/apis/datastore-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,41 @@ These options can be configured at
Field Names
~~~~~~~~~~~

Read about changes to the Datastore field names when `upgrading to DKAN 7.x-1.16 <../components/datastore.html#important-notes-when-upgrading-dkan-from-previous-versions-to-7-x-1-16>`_
In order to get data for specific fields, you need to add the argument 'fields' as an array to your request:

::

http://example.com/api/dataset/search?resource_id=d3c099c6-1340-4ee5-b030-8faf22b4b424&fields[]=country

If you wish to get multiple fields, add the 'fields[]' parameter followed by the field name as many times as fields needed, for example:

::

http://example.com/api/dataset/search?resource_id=d3c099c6-1340-4ee5-b030-8faf22b4b424&fields[]=field_name_1&fields[]=field_name_2

Important Note: if the resource you are querying has a file with column names which contains spaces or capital letters (e.g. 'School Name'), you should NOT specify the field in the request in that way, instead, it should be referenced as lower case with underscores instead of spaces (e.g. school_name).

Read more about changes to the Datastore after upgrading to DKAN 7.x-1.16 `here <../components/datastore.html#important-notes-when-upgrading-dkan-to-7-x-1-16-from-previous-versions>`_

Filters
~~~~~~~

If you wish to filter data based on the value of a field, you'll need to specify the 'filters' parameter in the request, it should be formatted like:

::

filters[field_name_1]=value,value2

When you need to specify filters for multiple fields, then you'll just join them with &, like this:

::

filters[field_name_1]=value&filters[field_name_2]=value2

So, for example you could execute the query:

::

http://example.com/api/dataset/search?resource_id=d3c099c6-1340-4ee5-b030-8faf22b4b424&filters[country]=AR,US

That query will return the records in which the 'country' is set to US or AR.

0 comments on commit 03f1b86

Please sign in to comment.