Retrieving User and Domain Data

Plesk XML API (XML API, and Command-Line Interface enable you to retrieve information about Plesk objects and edit these objects. However, if you need to retrieve properties of Plesk users and domains, you can easily do this by means of the pm_Client and pm_Domain classes. We recommend that you use these classes for retrieving information about session objects as described below.


The pm_Client class represents a Plesk user account. This class supports retrieving information about a user either by their ID or by their username. It also lets you identify a user's account type: administrator, reseller, or customer. Finally, this class contains the getProperty method that lets you retrieve any user information from the table clients in the Plesk database psa. Examples of pm_Client usage are provided below.

1. Retrieving user information by their ID and identifying their username and account type:

    $client = pm_Client::getByClientId($id);
    echo "Hello, {$client->getProperty('login')}";
    if ($client->isAdmin()) {
    	echo "You are admin";
    } elseif ($client->isReseller()) {
    	echo "You are reseller";
    } elseif ($client->isClient()) {
    	echo "You are customer";

2. Retrieving user ID by their username:

    $client = pm_Client::getByLogin($login);
    echo "Your ID is {$client->getId()}";

The pm_Domain class represents a domain hosted in Plesk. This class supports retrieving information about a domain by its ID. Additionally, this class contains the getProperty method that lets you retrieve any domain information from the table domains in the Plesk database psa.

An example of pm_Domain usage is provided below.

    $domain = new pm_Domain($domainId);
    echo "Domain name: {$domain->getName()}";
    echo "Created at {$domain->getProperty('cr_date')}";
Session Control

If your extension needs to retrieve information from the user that is currently logged in to Plesk, use the pm_Session class.

Usage Examples

For restricting user access to the extension, retrieve the pm_Client object. The following code restricts access for all users except administrators:

    if (!pm_Session::getClient()->isAdmin()) {
    	throw new pm_Exception('Permission denied');

If an administrator or a reseller is logged in the Control Panel as one of their customers, you can retrieve the customer's identifier the following way:

    if (pm_Session::isImpersonated()) {
    	$clientId = pm_Session::getImpersonatedClientId();

Additionally, if the session is open in the Control Panel, you can retrieve information about the domain that is currently being operated on:

    $domain = pm_Session::getCurrentDomain();

$domain in this example is an instance of the pm_Domain class.

If Plesk is unable to retrieve the domain, a pm_Exception will be thrown.