• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

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