September 1, 2013


Cancel software licenses by IP

Cancel all software licenses associated with a specific IPv4 address
Hey, listen!
This example contains deprecated methods or syntax and needs to be updated. Please use caution when using.
#!/usr/bin perl
use warnings;
use strict;
use Data::Dumper;
use SoftLayer::API::SOAP;

my $api_username = '';
my $api_key = '';

my $cPanelIp = '127.0.0.1';
my $billingItemId;
my $accountId;

my $accountClient = SoftLayer::API::SOAP->new('SoftLayer_Account', undef, $api_username, $api_key);
my $billingClient = SoftLayer::API::SOAP->new('SoftLayer_Billing_Item_Cancellation_Request', undef, $api_username, $api_key);

my $objectMask = "mask.billingItem.id";
$accountClient->setObjectMask($objectMask);

my $licenses = $accountClient->getActiveVirtualLicenses()->result;

for my $i (0 .. $#{$licenses}) {
    my $license = $licenses->[$i];
    if ($cPanelIp eq $license->{'ipAddress'}) {
        $billingItemId = $license->{'billingItem'}->{'id'};
        $accountId = $license->{'accountId'};
    }
}

my $cancellationRequestTemplateObject = {
    'items' => [
            {
                'billingItemId' => $billingItemId,
            }
    ],
    'accountId' => $accountId
};

my $result = $billingClient->createObject($cancellationRequestTemplateObject);
print Dumper($result);