• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Resolved retrieve site-id using the PHP API (/plesk/api-php-lib)

Beat Stieger

New Pleskian
How can i properly get a site-id using the PHP library offered by Plesk?

I only get the following Object informations using $client->Site()->get('name','domain-a-a.ch'):
PleskX\Api\Struct\Site\GeneralInfo Object
(
[name] => domain-b-b.ch
[asciiName] => domain-b-b.ch
[guid] => 66668abc-1234-1234-abc4-1234a1ab1234
[status] => 0
[description] =>
)

If i interpret well the XML response documented under Getting Information About Sites, there should be returned an <id> as well...
 
Hello,
Retrieving site id is not supported at the moment. However, this is an open source project and you can help us by contributing to plesk/api-php-lib
 
If anyone else runs into this problem: You can use the "request" method of your API client instance to get an object representation of the raw data. You will have to construct the XML Request yourself, but you get all the data that is otherwise unaccessible.

//Code exmaple:

function get_site_data($domain) {
//get client instance
$client = new \PleskX\Api\Client($server_ip);
$client->setCredentials($api_user, $api_pw);

//construct request
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><packet></packet>', null, false);
$site = $xml->addChild('site');
$get = $site->addChild('get');
$filter = $get->addChild('filter');
$filter->addChild('name', $domain);
$dataset = $get->addChild('dataset');
$dataset->addChild('gen_info'); //optional meta data

//return result
return $client->request($xml);
}

//Output object structure:

object(PleskX\Api\XmlResponse) (4) {
["status"]=> string(2) "ok"
["filter-id"]=> string(11) "example.com"
["id"]=> string(1) "1" // ----> that's what you are searching for
["data"]=> object(PleskX\Api\XmlResponse) (1) {
// ---various other meta data, based on "/filter/dataset" node---
}
}
 
Back
Top