This article provides valuable examples of how to use filters in the Applaud platform.
When querying the API with the GET function, you can use filters to limit the number of responses returned. For example, the limit filter reduces the results returned by your specified number. We recommend you include the limit filter so that you don't waste time waiting for many responses to be returned.
Use a JSON validation tool to ensure your JSON is correct before using the filter on the model's API page, for example, JSON Online Validator and Formater - JSON - Lint.
Limit
{"limit":10} | This default filter reduces the number of results to your specified number. We include this on some queries, set to 10 by default. You can amend the number to increase or decrease the returned results limit. |
Where - and its operators
The where filter is quite a useful filter to find the data you want. There are several operators you can use with this filter. The basic filter is used to specify a value for a property.
{"limit": 10, "where": {"firstName": "Annalise"}} | Find results that contain fields with specific values. Remember to include the limit filter. In this example, firstName is the property name, and Annalise is the property value. |
And
Use this operator to specify multiple conditions.
{"limit": 10, "where": {"and":[{"role": "manager"}, {"department": "finance"}]}} | For example, find people who are a manager in the finance department. It will only return people with both conditions. |
Or
Use this operator to find results with either one value or another value.
{"limit": 10, "where": {"or":[{"role": "manager"}, {"department": "finance"}]}} | For example, find people who are a manager or anyone in the finance department. It will return everyone in the finance department and managers who aren't in the finance department. |
inq - Inquire
With this operator, you can specify the property values you want to be returned.
{"limit": 10, "where": { "role": { "inq": ["InsideIR35", "OutsideIR35"]}}} | For example, you could look for people with the role of contractor, who are inside and outside of IR35. |
nin
You can query the data and exclude results based on specific values.
{"limit": 10, "where":{"role":{"nin":["manager"]}}} | In this example, we've excluded all users who have their role set to "manager." |
Order
{"limit": 10, "order": "lastName ASC"} | Order your query results in either ASC - ascending or DESC - descending order. In this example, we've ordered by the property lastName in ascending order. |
Field select
{"limit": 10, "fields": {"firstName": false}} | All fields, or properties, return with their values by default. To reduce the properties you see, you can set the field filter to false, which doesn't return the property and its value. You can also set a property to true to ensure the property value is returned. Note, that you can't hide the "modelName" field. |
Without field select filter | With field select fitler |
Include
{"limit":10, "include": ["work_country"]} |
Includes results from related models in a query, for example, models with belongsTo or hasMany relations. The included model properties are shown nested in the results. |