Order domain to an existing account (Perl)

This example shows how to use Perl to connect to our XML-RPC server and register a domain that is paid by Loopia PrePaid credit. The example also adds domain configuration to send all of the visitor traffic to 127.0.0.1 in both the domain itself and any subdomains.

Note that the following code example contains no error handling for the sake of readability.

Example

Below you find the code for the example above.

#!/usr/bin/perl  
  
use RPC::XML;  
use RPC::XML::Client;  
use Data::Dumper;  
use Encode;  
  
my $global_check_domain_server_url =   
   'https://api.loopia.se/RPCSERV';  
  
my $global_username = "YOUR_USERNAME";  
my $global_password = "YOUR_PASSWORD";  
  
my $client =   
   RPC::XML::Client->new($global_check_domain_server_url);  
$RPC::XML::ENCODING = "UTF-8";  
  
my $response = $client->simple_request('orderDomain',  
   $global_username, $global_password, $domain,  
   RPC::XML::boolean->new(1));  
  
print "Account created: " . Dumper($response) . "\n\n";  
die unless defined($response);  
  
$response = $client->simple_request('getDomain', $global_username,  
   $global_password, $domain);  
  
print "Domain object: " . Dumper($response) . "\n\n";  
  
my $reference_no = $response->{"reference_no"};  
my $amount = $response->{"unpaid_amount"};  
  
$response = $client->simple_request('payInvoiceUsingCredits',  
   $global_username, $global_password,  
   RPC::XML::string->new($reference_no));  
  
print "Invoice $reference_no paid ($amount SEK): " .   
   Dumper($response) . "\n\n";  
  
$response = $client->simple_request('addSubdomain',  
   $global_username, $global_password, $domain, "\@");  
     
print "Subdomain added: " . Dumper($response) . "\n\n";  
  
$response = $client->simple_request('addZoneRecord',  
   $global_username, $global_password, $domain, "\@",  
   { "type" => "A", "priority" => undef, "ttl" => "300",  
   "rdata" => "127.0.0.1" });  
     
print "Record added: " . Dumper($response) . "\n\n";  
  
$response = $client->simple_request('addSubdomain',  
   $global_username, $global_password, $domain, "*");  
  
print "Subdomain added: " . Dumper($response) . "\n\n";  
  
$response = $client->simple_request('addZoneRecord',  
   $global_username, $global_password, $domain, "*",  
   { type => "A", "priority" => undef, "ttl" =>"300",  
   "rdata" => "127.0.0.1" });  
     
print "Record added: " . Dumper($response) . "\n\n";  
Was this article helpful?

Related Articles