For PHP, we recommend using Zend Framework 1. You can download it from http://framework.zend.com/downloads/latest#ZF1. It will handle the https connection transparently.

  1. Load the necessary classes and perform initialization.
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
  1. Define variables. Be sure to use https in the URL part.
$apiUrl = 'https://ka.demo.plesk.com:7050/xmlrpc';
$apiLogin = 'API_LOGIN'; # the username for access to the API
$apiPassword = 'API_PASSWORD';  # the password for access to the API
$keyNumber = "PLSK.00052355";  # the key to retrieve

3. Prepare the necessary structs. The AuthInfo struct consists of two entities (login, password). The main function has two parameters. We store them in the array $callParameters[].

$authInfo = new Zend_XmlRpc_Value_Struct(array(
  'login' => new Zend_XmlRpc_Value_String($apiLogin),
  'password' => new Zend_XmlRpc_Value_String($apiPassword),
));
$callParameters = array(
  $authInfo,
  new Zend_XmlRpc_Value_String($keyNumber)
);
  1. Establish a connection to the KA server and make a call.
$api = new Zend_XmlRpc_Client($apiUrl);
$api->setSkipSystemLookup();
$result = $api->call('partner10.retrieveKey', $callParameters);

5. Check the response code. Process the data if the call was successful, otherwise, perform some error handling. You can find the current key number in $result[“keyNumber”]. The actual key file is in $result[“key”]. The key file is encoded in BASE64, so you still need to decode it.

if ($result["resultCode"] == 100) {
  # Process data here!
  echo $result["key"]; # prints key
  # print_r($result); # print the entire array
} else {
  echo "Result Code: ".$result["resultCode"]."\n";
  echo "Result Desc: ".$result["resultDesc"].$result["faultString"]."\n";
}

Now you can process the Key file, store it on a file system or in a database. Or directly install it in the software.