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 name that is paid for using LoopiaPREPAID credit. The example also adds DNS configuration to send all visitor traffic to 127.0.0.1, both for the domain itself and for any subdomains.

For clarity, the following code example contains no error handling.

Example

The code for the example is shown below.

#!/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