Filters
This article explains the different data types on which filters are supported in the API. The attributes in the API response can be 6 different types. Each one of them have a filter structure defined.
Here we will explain each of the data types and how to apply a filter on the data.
The different types of data are
- String
- Enums
- Number
- Date
- Source
- Custom Fields
To apply a filter you can use the filter object as shown below in the API request. The body of the request supports the filter object. There are 5 keys supported in filter object which are:
- field_id: The field to filter by, e.g., user_name, user_status.
- field_order: Applicable for numeric filters like usage. Allowed values: gt, lt, gte, lte, eq, range - ["gte","lte"]
- field_values: Values to filter the field by
- sort_by: Sort options like {user_name: 1} for ascending or {user_name: -1} for descending
- negative: If true, the filter will exclude the specified values mentioned in field_values
General Filter Example:
curl --request POST \
--url https://api-ext.zluri.com/v2/users \
--header 'accept: application/json' \
--header 'api-key: eAZxofpBDRtWl51PFnLQm633' \
--header 'content-type: application/json' \
--data '
{
"filter_by": [
{
"field_id": "user_name",
"field_values": [
"anthony"
]
}
]
}Filtering Examples:
Given below are filters for different data types.
Enums:
The keys like ‘status’ , ‘user_account_type’ where there is set of possible values, you can use those values in field_values to filter by the value.
Example:
{
"field_id": "user_status",
"field_values": ["active", "inactive"]
}
String
For free text fields like user_name & user_email you can filter by the value by sending the field_id and field_values in the below format.
{
"field_id": "user_name",
"field_values": ["anthony"]
}
Date
For date fields the operator can be passed in the field_order key as shown below. If the query you have to run is for date range, Please paas both gte & lte operators.
{
"field_id": "user_created_at",
"field_order": ["gte", "lte"],
"field_values": ["2023-10-29", "2023-10-31"],
}
Number For number fields the operator can be passed in the field_order key as shown below.
{
"field_id": "user_usage",
"field_values": [40, 100],
"field_order": ["gte", "lte"]
}
Custom Field
Custom field accepts a nested object type filter where you need to paas the custom_field_id and custom_field_values in the field_values object.
{
"field_id": "custom_fields",
"field_values": {
"custom_field_id": "679b613f315ee0a11cb67bd1",
"custom_field_values": ["India"]
}
}
Source
Source is also an object with a format where you need to paas the key, value_type & value as shown below.
{
"field_id": "source_array",
"field_values": [
{
"key": "org_integration_id",
"value_type": "objectId",
"value": ["663361257ba6fa1c72b63760"]
}
]
}
Search Query
The search_query parameter lets you search users by name or email (supports partial matches).
GET /users?search_query=johnUpdated about 2 months ago
