Filter & Sort
When working with list APIs, it can be convenient to filter and sort results on the API server so clients can avoid additional network requests and save computation.
Filtering and sorting are powered by Information Fields. Refer to the previous guide on Information Fields to understand how they are represented in the API.
Filtering
List API results can be filtered by providing the optional filter query parameter as a JSON-encoded string, with each entry representing the fieldName and value of the corresponding Information Field.
Filtering with the filter query parameter is supported only on resources that include Information Fields. Refer to the API spec for additional predefined filters that can be passed as query parameters.
The following example queries participants that work at a specific company, indicated by the participant Information Field Company. The filter JSON can be constructed as follows:
"filter": {
"Company": "Sterling Enterprise"
}
To query the list items, include the filter JSON as an encoded string in the Sessions GET request. Here’s an example of what the encoded query string could look like:
https://api.condens.io/v1/participants?filter=%7B+%22Company%22%3A+%22Sterling+Enterprise%22+%7D
Sorting
List API results can be sorted using the optional sort query parameter as an encoded string. For ascending sorts, it can take the value name or the fieldName of any Information Field in that resource. To sort results in descending order, prefix the sort value with a hyphen, for example -name or -date.
Although the API server does not enforce type restrictions on the Information Field used for sorting, it is recommended to use Information Fields with fieldType String or Number to get deterministic results.
Sorting by Information Field name is supported only on resources that include Information Fields.
The following example queries recently created Projects. All projects contain the default Information Field Start Date, which is initially set to the creation date of the Project, so we can use it as the sort value with the descending order prefix (-).
https://api.condens.io/v1/projects?sort=-start+date
Tip: Combine filter and sort query parameters with the pageSize pagination parameter to further limit results. View the next guide on pagination to learn more.