Filtering and searching
Most list (or index) endpoints will allow you to filter or search using query parameters. Common use cases are:
- Find a worker by their ID
- Find a client by their full name
- Only return visits that are scheduled to happen next week
- Only return rates which are more than $50
Filters
Each filter is made up three parts:
- Attribute: the available filterable query parameters that can be used for each resource
- Operator: defaults to
equals, but also supports other operators such asgreater thanetc. - Value: the static value you want to apply to the filter
Operators
| Operator | Description | Example |
|---|---|---|
eq | Equal to (default) | attribute=99 |
ne | Not equal to | attribute[ne]=99 |
gt | Greater than | attribute[gt]=99 |
gte | Greater than or equal to | attribute[gte]=99 |
lt | Less than | attribute[lt]=99 |
lte | Less than or equal to | attribute[lte]=99 |
Filtering on null
By not providing a value to a filter, you can filter by null
| Operator | Description | Example |
|---|---|---|
eq | Equal to | attribute[eq] |
ne | Not equal to | attribute[ne] |
Arrays
Some fields can accept multiple values (ie. those ending in [] and accepting an array parameter). In this case, multiple values can be provided as follows:
?ticket_template_ids[]=1&ticket_template_ids[]=2
Examples
We could apply the following filters to the visits endpoints:
| Filter | Description |
|---|---|
?client_id=99 | Return visits for the client with an ID of 99 |
?client_id=99&rating[lt]=5 | Return visits for the client with an ID of 99, that had a rating of less than 5 |
?actual_start_time[gte]=2023-01-01 | Return visits that started on, or after, January 1st, 2023 |
?actual_start_time[gte]=2023-01-01&actual_start_time[lte]=2023-01-07 | Return visits that started between January 1st-7th, inclusive |
?worker_id[eq] | Return visits where the worker_id is null |
As an example of other field types, we could apply these filters to the workers endpoint:
| Filter | Description |
|---|---|
?archived=true | Return archived workers |
?archived=false | Return active (non-archived) workers |
Search
This can be done either by passing a value the q parameter and search against all specified attributes, or search against a specific attribute by specifying in the parameter.
Examples
We could search for clients by using the following parameters on the List all clients endpoint:
| Filter | Description |
|---|---|
?q=Name or [email protected] | Return clients that match the search parameters |
?q[full_name]=Name | Search clients by profile name |
?q[email][email protected] | Search clients by profile email address |
The searchable attributes are specified in the parameters documentation for each endpoint.
Updated 9 months ago
