Administration API: How to create a search query
To get some items from the server, use a <Interface>.get request. It returns a list of items and total number of items without dependency on condition that limits the output. The following examples should help you to understand how to create a search query by using Kerio APIs Client Library for PHP.
Here is the basic form of the <Interface>.get request to obtain a list of items (Users.get, MailingLists.getMlUserList, Resources.get, Domains.get, Content.getCustomRuleList,..).
The following structure is used in get requests where server sorting is available. There are some methods where params are omitted (i.e. Content.getBlackListList)
$params = array(
"query" => array(
"fields" => array("<field1>", "<field2>"),
"orderBy" => array(array(
"columnName" => "<columnname>",
"direction" => "<direction>"
)),
"combining" => "<combining>",
"conditions" => array(array(
"fieldName" => "<fieldname>",
"comparator" => "<comparator>",
"value" => "<value>"
)),
"start" => <start>,
"limit" => <limit>
),
"<optional: some global condition to search in, i.e. domainId>"
);
$result = $api->sendRequest('<Interface>.get', $params);
Legend
- fields: A list of fields you want to return.
- orderBy: Sorting order. You can define direction and columnName (field) for sorting. Allowed directions: Asc, Desc.
- combining: The list of conditions can be combined by either 'ORs' or 'ANDs'. Combination of both is not supported.
- conditions: The list of conditions you want to use as search criteria.
- comparator: The operator between fieldName and value.
- start: Number of items to skip before filling a result list. The default value is 0.
- limit: Number of items to put to a result list (if there are enough items). The default value is -1 (Unlimited).
Example: Get all users from the domain
To get all users from a domain, the request can be written in a shorten format. You can specify fields to be returned. If it is omitted (empty "query" array must always be defined), the server returns all available fields for the entity.
$params = array(
"query" => array(
"fields" => array("loginName")
),
"domainId":"keriodb://domain/..."
);
$result = $api->sendRequest('Users.get', $params);
This request returns a list of all users unsorted. To have the items alphabetically, you can define the type of sorting.
$params = array(
"query" => array(
"orderBy" => array(array(
"columnName" => "loginName",
"direction" => "Asc"
)),
),
"domainId":"keriodb://domain/..."
);
$result = $api->sendRequest('Users.get', $params
Example: Limited range of users
If you want to find the first 50 users starting on index 20, add start and limit parameters to the query.
$params = array(
"query" => array(
"start" => 20,
"limit" => 50
),
"domainId":"keriodb://domain/..."
);
$result = $api->sendRequest('Users.get', $params);
Example: Filter users
Do you want to return only users which contain the string 'Brown' in their names? You need to parametrize the query in the request by a condition.
$params = array(
"query" => array(
"conditions" => array(array(
"fieldName" => "QUICKSEARCH",
"comparator" => "Like",
"value" => "Brown"
))
),
"domainId":"keriodb://domain/..."
);
$result = $api->sendRequest('Users.get', $params);
Legend
- QUICKSEARCH is currently implemented only in the "Users.get" method. Behavior of quicksearch is different for each operator:
- QUICKSEACH = "x" is equal to: (loginName = "x") OR (fullName = "x")
- QUICKSEACH LIKE "x*" is equal to: (loginName LIKE "x*") OR (fullName LIKE "x*")
- QUICKSEACH <> "x" is equal to: (loginName <> "x") AND (fullName <> "x")