Perl

partner10.createKey()

#!/usr/bin/perl

# Retrieve key and write to local file

use Frontier::Client;

use MIME::Base64;

$login = 'API_LOGIN'; # username for API

$pass = 'API_PASSWORD'; # password for API

$url = 'https://ka.demo.plesk.com:7050'; # server url

$server = Frontier::Client->new( 'url' => $url, 'debug' => 1 );

%authInfo = ( login => $login,

           password => $pass);

%serverInfo = (ips => ['192.168.0.1'],
               macs => []);

print "Invoking partner10.createKey method ...\n";

$results = $server->call('partner10.createKey', \%authInfo,\%serverInfo, 'CLIENT_LOGIN','PLESK_8',['30_DOMAINS']);

if($results->{resultCode} != 100){

  die("\nError creating new key\n");

}

$key_number = $results->{mainKeyNumber};

print "\nSucessfully created new $key_number\n";

partner10.retrieveKey()

# Retrieve key and write to local file

# plug in required modules (xml-rpc client and base64 decoder/encoder)
use Frontier::Client;
use MIME::Base64;

# define variables related to KA API
$login = 'API_LOGIN'; # username for API
$pass = 'API_PASSWORD'; # password for API
$url = 'https://ka.demo.plesk.com:7050'; # server url
$key = 'PLSK.00052355'; # key to retrieve

# create xmlrpc client instance point to KA service
$server = Frontier::Client->new( 'url' => $url, 'debug' => 1 );

# create authInfo structure 
%authInfo = ( login => $login,

           password => $pass);

print "Retrieving $key ...\n";

# invoke KA api method partner10.retrieveKey
$results = $server->call('partner10.retrieveKey', \%authInfo, $key);

# check result code 
if($results->{resultCode} != 100){

  die("\nError retrieving key: $key\n");

}

# get base64 encoded key number from response, decode it and print
$key_number = $results->{keyNumber};
$key_file = decode_base64($results->{key}->value()) . "\n";
open(KEY, ">$key.sh");
print KEY $key_file;
close(KEY);

print "\nSucessfully retrieved key $key as $key.sh\n";