Kerio Connect Administration API - setting user quotas


Recent versions of Kerio Connect support the "Administration API for Kerio Connect". This allows you to perform administrative tasks through scripting. This can be very convenient for making mass changes based on specific conditions.

For example, one of my customers wants to apply a 1 MB quota to any user who has never logged in and does not already have a quota set. That may sound like a strange request, but they are a large company and have many users that aren't necessarily using email yet. When they originally setup users, they did not assign quotas, but have started doing so to some users. Going in to find all the inactive users would be a lot of work to do manually, but an API script can do it quickly and easily.

I modified one of the example scripts that Kerio provides and also got some help from Lukas Nemec at the Kerio Developers forum. I had been playing with an earlier version of the API and was causing myself some trouble by reading current documentation without upgrading. Once I installed the current version, things worked MUCH better :)

To use this script, you'll need to download the Kerio api and install it per the instructions in the reference documentation found at the same link.

You'll also want to look at the documentation at

The script as presented here does not do extensive error checking. I have tested it against test servers, but (as usual) you need to understand what this does and you will use it at your own risk.

The script could be made more efficient by building an array of user id's and setting them all at once rather than individually. I didn't want to complicate this by doing that; it's easier to understand without it.

Here is sample output from two back-to-back runs.

 * Administration API Sample Application.
 * Display all users with any administrator rights.
 * @copyright Copyright © 1997-2011 Kerio Technologies s.r.o.
 * and modified by A.P. Lawrence
 * See
        <meta http-equiv="Content-type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="style.css">
        <link rel="shortcut icon" href="favicon.ico">
        <title>Administration API</title>

require_once(dirname(__FILE__) . '/examples/class/MyApi.php');

/* Application details */
$name = 'Set user quota';
$vendor = 'A.P. Lawrence';
$version = '1.0';

$hostname = '';
$username = 'Admin';
$password = '753tkerioaHw2s93!';

$Api = new MyApi($name, $vendor, $version);

/* Local functions */
function getDomainList() {
    global $Api;
    $method = 'Domains.get';
    $params = array(
        'query' => array(
            'fields' => array(
    $result = $Api->sendRequest($method, $params);
    return $result['list'];
function getUserList($domainId) {
    global $Api;
    $method = 'Users.get';
    $params = array(
        'query' => array(
            'fields' => array(
            'orderBy' => array(array(
                'columnName' => 'loginName',
                'direction' => 'Asc'
        'domainId' => $domainId
    $result = $Api->sendRequest($method, $params);
    return $result['list'];

/* Main application */
print "<h1> Display users with no login and set quota</h1>";

try {

    /* Register application */
    /* Login */
    $login = $Api->login($hostname, $username, $password);
    /* Get domain list */
$domainList = $Api->getDomains(array('id', 'name'));
    foreach ($domainList as $domain) {
            $userList = $Api->getUsers(array('id','loginName',
            'fullName', 'diskSizeLimit', 'lastLoginInfo'),

        foreach ($userList as $user) {
            $quota = $user['diskSizeLimit']['limit']['value'];

            if (! $user['lastLoginInfo']['dateTime']) {
                $set="Already set";

                if (false == $user['diskSizeLimit']['isActive']) {
                    $set="Will set to 1 MB";
                    $params = array(
                        'userIds' => array(

                        'pattern' => array(
                            'diskSizeLimit' => array(
                                'isActive' => TRUE,
                                'limit' => array(
                                    'value' => 1,
                                    'units' => 'MegaBytes'

                    $response = $Api->sendRequest('Users.set', $params);

                    $quota = '(From unlimited)';
                $username = $user['loginName'] . '@' . $domain['name'];
                $fullname = $user['fullName'];

                printf('%s (%s) %s %s <br>', $username, $fullname, $set , $quota);

} catch (Exception $error) {
    /* Catch possible errors */
    print $error->getMessage();

/* Logout */
if(isset($login)) {

print '<hr>';
print date(DATE_RSS);


Got something to add? Send me email.

(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Administration API - setting user quotas

Increase ad revenue 50-250% with Ezoic

More Articles by

Find me on Google+

© Anthony Lawrence

Kerio Connect Mailserver

Kerio Samepage

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

privacy policy