Filter

There are two special concepts you can make use of in the filter param: grouping and operators.

Grouping

You might want to write queries where your filters are more complicated than filter[first_name]=John&filter[last_name]=Doe You can accomplish this with filter groups using the and and or keywords - filter[or][0][first_name]=John&filter[or][1][first_name]=Jane.

Note: make sure to use numeric groups [0] after the and and or keywords

Operators

You may want to query with operators other than equals like: searching date ranges, matching an item in a collection, or matching part of a string.

To do this, you can post-fix filters with operators. They are specified like __[operator] (two underscores):

  • __gt (greater than)
  • __gte (greater than or equal)
  • __lt (less than)
  • __lte (less than or equal)
  • __in
  • __notin
  • __isnull
  • __notnull
  • __contains
  • __starts
  • __ends

Examples

  • Simple Filtering:
    Filter resources to those whose first_name is mad &filter[first_name]=mad
  • Multi-field Filtering:
    Filter resources to those whose first_name is mad and whose last_name is max &filter[first_name]=mad&filter[last_name]=max
  • Relation Filtering:
    Filter resources to those whose league's season's program id is 123 and whose league is active &filter[league.season.program_id]=123&filter[league.is_active]=true
  • Filter Operators:
    Filter events to those between 2019-03-01 and 2019-03-10 &filter[start_date__gte]=2019-03-01&filter[end_date__lte]=2019-03-10
  • And/Or Group Filtering:
    You can also create sql or/and groups in the filter parameter. This example filters resources to those whose first_name is mad OR max &filter[or][0][first_name]=mad&filter[or][1][first_name]=max
  • Composite And/Or Group Filtering:
    It can be a little tricky making composite and-or groupings. To do it make sure to start with a root AND group. This example will filter responses to those whose first name is mad and last name is max OR michael &filter[and][0][first_name]=mad&filter[and][1][or][0][first_name]=max&filter[and][1][or][1][first_name]=michael