When an XML API packet is ready, it should be wrapped into an HTTP header and sent to the specified server. To perform these tasks, we suggest using any HTTP/FTP client library. This topic demonstrates how this can be done in PHP using the CURL engine - a free and open client-side URL transfer library.
To simplify working with XML API, you can use the PleskApiClient class. To prepare an XML API client, you need to create an instance of PleskApiClient and initialize it:
$client = new PleskApiClient($host);
After that, prepare a packet:
And then perform a request:
$response = $client->request($request);
You should be able to see a response for the “get_protos” command, similar to the following:
These XML data can be parsed by an XML parser such as SimpleXML or DOMDocument.
The PleskApiClient class allows performing authorization by using a secret key instead of a username and password pair. For example:
$client->setSecretKey('<here is the key>');
Internally the PleskApiClient class uses curl to perform a request. It defines the URL, sets the necessary headers and sets the request body:
The code of this example and the PleskApiClient class are located at https://github.com/plesk/api-examples/tree/master/php.