Filtering
We provide a generic way to filter and search results whenever a GET request to a resource returns a collection of records.
When listing records, you’ll often only want to return those which match specific criteria, such as listing all the notices of a given type or those created after a particular date.
The ‘Filter’ Parameter
This is done using the ‘filter’ parameter on the request. This parameter can contain a number of keys which are the combination of the attribute name and operator, followed by the value.
Example request filtering notices created before 1st January 2025
curl curl -X GET https://api.sorryapp.com/v1/pages/:page_id/notice \
-d "filter[created_at_gt]=2025-01-01" \
-H "Authorization: Bearer token"
Filtering ‘Included’ Records
You can also apply these exact same filters against collections nested under a singular resource which you’ve included using the ‘?include’ parameter.
Here you have to submit a nested parameter within filter which corresponds to the name of the included collection, this, in turn, contains the filters for that collection.
Example request getting a status page with notices created before 1st January
curl curl -X GET https://api.sorryapp.com/v1/pages/:page_id \
-d include="notices"\
-d "filter[created_at_gt]=2025-01-01" \
-H "Authorization: Bearer token"
Available Operators
The examples above both use the *_gt operator, but there are lots of other useful operators you can use in much the same manner.
Operator | Description | Example |
---|---|---|
*_eq | The attribute equals the value provided. | ?filter[subject_eq]="Database Maintenance" |
*_not_eq | The attribute does not equal the value provided. | ?filter[subject_not_eq]="Database Maintenance" |
*_matches | The attribute partially matches the value LIKE. | ?filter[subject_matches]="%Maintenance" |
*_cont | The attribute contains the value. | ?filter[subject_cont]="Maintenance" |
*_gt | The attribute is greater than the value provided. | ?filter[created_at_gt]="2021-05-06" |
*_lt | The attribute is less than the value provided. | ?filter[created_at_lt]="2021-05-06" |
*_gteq | The attribute is greater than or equal to the value provided. | ?filter[created_at_gteq]="2021-05-06" |
*_lteq | The attribute is less than or equal to the value provided. | ?filter[created_at_lteq]="2021-05-06" |
*_present | The attribute is not blank or empty. | ?filter[began_at_present] |
*_blank | The attribute is blank or empty. | ?filter[began_at_blank] |
*_in | The attribute is contained in the list provided by the value. | ?filter[type_in][]="planned"&filter[type_in][]="unplanned" |
*_not_in | The attribute is not contained in the list provided by the value. | ?filter[type_not_in][]="planned"&filter[type_not_in][]="unplanned" |