• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Api plesk 12 get site fails

Jose Joaquin

New Pleskian
Hello Guys,

Im using the plesk api and reading the manual for the api, in http://download1.parallels.com/Plesk/Doc/es-ES/online/plesk-api-rpc/66586.htm said that parsing the 1st example get all information about sites but is not working.


The result is:

<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.6.0">
<site>
<get>
<result>
<status>ok</status>
</result>
</get>
</site>
</packet>

But if i filter by domain name works and get only the domain name that i filter. How to get information about all sites?

Best Regards.
 
Hello Guys,

Me again, the same thing happens with resellers, witht he xml

<packetversion="1.6.0.0">
<reseller>
<get>
<filter/>
<dataset>
<gen-info/>
<stat/>
<permissions/>
<limits/>
<ippool/>
</dataset>
</get>
</reseller>
</packet>

You get this result:

<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.0.0">
<reseller>
<get>
<result>
<status>ok</status>
</result>
</get>
</reseller>
</packet>


How to retrieve all resellers account??? If the manual of the api is wrong please fix it.

Best Regards.
 
Try to use this example:


Code:
<?php


/**

* Reports error during API RPC request

*/

class ApiRequestException extends Exception {}


/**

* Returns DOM object representing request for information about all available domains

* @return DOMDocument

*/


function domainsInfoRequest()

{

      $xmldoc = new DomDocument('1.0', 'UTF-8');

      $xmldoc->formatOutput = true;


      // <packet>

      $packet = $xmldoc->createElement('packet');

      $packet->setAttribute('version', '1.6.2.0');

      $xmldoc->appendChild($packet);


      // <packet/domain>

      $domain = $xmldoc->createElement('domain');

      $packet->appendChild($domain);


      // <packet/domain/get>

      $get = $xmldoc->createElement('get');

      $domain->appendChild($get);


      // <packet/domain/get/filter>

      $filter = $xmldoc->createElement('filter');

      $get->appendChild($filter);


      // <packet/domain/get/dataset>

      $dataset = $xmldoc->createElement('dataset');

      $get->appendChild($dataset);


      // dataset elements

      $dataset->appendChild($xmldoc->createElement('hosting'));

      $dataset->appendChild($xmldoc->createElement('gen_info'));


      return $xmldoc;

}

/**

* Prepares CURL to perform the Panel API request

* @return resource

*/

function curlInit($host, $login, $password)

{

      $curl = curl_init();

      curl_setopt($curl, CURLOPT_URL, "https://{$host}:8443/enterprise/control/agent.php");

      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

      curl_setopt($curl, CURLOPT_POST,           true);

      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

      curl_setopt($curl, CURLOPT_HTTPHEADER,

             array("HTTP_AUTH_LOGIN: {$login}",

                    "HTTP_AUTH_PASSWD: {$password}",

                    "HTTP_PRETTY_PRINT: TRUE",

                    "Content-Type: text/xml")

      );


      return $curl;

}

/**

* Performs a Panel API request, returns raw API response text

*

* @return string

* @throws ApiRequestException

*/

function sendRequest($curl, $packet)

{

      curl_setopt($curl, CURLOPT_POSTFIELDS, $packet);

      $result = curl_exec($curl);

      if (curl_errno($curl)) {

             $errmsg  = curl_error($curl);

             $errcode = curl_errno($curl);

             curl_close($curl);

             throw new ApiRequestException($errmsg, $errcode);

      }

      curl_close($curl);

      return $result;

}


/**

* Looks if API responded with correct data

*

* @return SimpleXMLElement

* @throws ApiRequestException

*/

function parseResponse($response_string)

{

      $xml = new SimpleXMLElement($response_string);

      if (!is_a($xml, 'SimpleXMLElement'))

             throw new ApiRequestException("Cannot parse server response: {$response_string}");

      return $xml;

}

/**

* Check data in API response

* @return void

* @throws ApiRequestException

*/

function checkResponse(SimpleXMLElement $response)

{

      $resultNode = $response->domain->get->result;


      // check if request was successful

      if ('error' == (string)$resultNode->status)

             throw new ApiRequestException("The Panel API returned an error: " . (string)$resultNode->result->errtext);

}


//

// int main()

//

$host = 'localhost';

$login = 'admin';

$password = 'setup';


$curl = curlInit($host, $login, $password);


try {


      $response = sendRequest($curl, domainsInfoRequest()->saveXML());

      $responseXml = parseResponse($response);

      checkResponse($responseXml);


} catch (ApiRequestException $e) {

      echo $e;

      die();

}


// Explore the result

foreach ($responseXml->xpath('/packet/domain/get/result') as $resultNode) {

      echo "Domain id: " . (string)$resultNode->id . " ";

      echo (string)$resultNode->data->gen_info->name . " (" . (string)$resultNode->data->gen_info->dns_ip_address . ")\n";

}


?>
 
IgorG,

Thank you very much, your solution works. Now i have another problem with resellers. Im trying to get all resellers with the xml:

"<packet version='1.6.0.0'><reseller><get><filter/><dataset><gen-info/></dataset></get></reseller></packet>"

But only get:
<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.6.0.0">
<reseller>
<get>
<result>
<status>ok</status>
</result>
</get>
</reseller>
</packet>


How to retrieve all resellers? Im using plesk 12.

Thank you very much.
 
Hello,

I come back to post the way i solved this problem. You can retrieve all resellers with the "<all/>" filter.

<packet version='1.6.0.0'><reseller><get><filter><all/></filter><dataset><gen-info/></dataset></get></reseller></packet>

Best Regards.
 
Back
Top