• Hi, Pleskians! We are running a UX testing of our upcoming product intended for server management and monitoring.
    We would like to invite you to have a call with us and have some fun checking our prototype. The agenda is pretty simple - we bring new design and some scenarios that you need to walk through and succeed. We will be watching and taking insights for further development of the design.
    If you would like to participate, please use this link to book a meeting. We will sent the link to the clickable prototype at the meeting.
  • Our UX team believes in the in the power of direct feedback and would like to invite you to participate in interviews, tests, and surveys.
    To stay in the loop and never miss an opportunity to share your thoughts, please subscribe to our UX research program. If you were previously part of the Plesk UX research program, please re-subscribe to continue receiving our invitations.
  • 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.

Plesk 11.0.9 API don't work

AndreaMaiese21

New Pleskian
I have used this 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.3.5');
$xmldoc->appendChild($packet);

// <packet/domain>
$domain = $xmldoc->createElement('site');
$packet->appendChild($domain);

// <packet/domain/get>
$get = $xmldoc->createElement('get');
$domain->appendChild($get);

// <packet/domain/get/filter>
$filter = $xmldoc->createElement('filter');
$get->appendChild($filter);

$name = $xmldoc->createElement('name','xxxxx');
$filter->appendChild($name);

// <packet/domain/get/dataset>
$dataset = $xmldoc->createElement('dataset');
$get->appendChild($dataset);

$hosting=$xmldoc->createElement('hosting');
$dataset ->appendChild($hosting);
// 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->site->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 = 'xxxx';
$login = 'xxxx';
$password = 'xxx';

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

try {
echo domainsInfoRequest()->saveXML();
$response = sendRequest($curl, domainsInfoRequest()->saveXML());
$responseXml = parseResponse($response);
checkResponse($responseXml);
//var_dump($response);
} catch (ApiRequestException $e) {
echo $e;
die();
}

// Explore the result
foreach ($responseXml->xpath('/packet/site/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";
}​

But don't find an existing site
 
Back
Top