November 23, 2017
# Cancel servers from a list of IPs
# This script looks for a server with a determinate IP address and delete it.
# It makes a single call to the cancelService() method in the
# SoftLayer_Billing_Item API service
# Important manual pages:
# License:
# Author: SoftLayer Technologies, Inc. <>
use lib 'C:/softlayerApis/perl/softlayer-api-perl-client-master/';
use SoftLayer::API::SOAP;
use Data::Dumper;

# Your SoftLayer API username and key.
my $username = 'set me';
my $key = 'set me';

# Adding an object mask to retrieve our billing items related to the servers
# for a list of the relational properties you can retrieve along with hardware.
my $object_mask = 'mask[billingItem]';

# The list of IPs from the servers you wish to cancel
my @ips_to_cancel = ('', '');

# Declaring a new API service object for the
# SoftLayer_Account API service
# SoftLayer_Billing_Item service
my $hardware_server_service = SoftLayer::API::SOAP->new('SoftLayer_Hardware_Server', undef, $username, $key);
my $billing_item_service = SoftLayer::API::SOAP->new('SoftLayer_Billing_Item', undef, $username, $key);

# Making the call to retrieve our hardware records along with their billing item.
# Setting the init parameter with the server Id

for my $ip_to_cancel (@ips_to_cancel) {
    my $server = $hardware_server_service->findByIpAddress($ip_to_cancel);
    if ($server->fault) {
        die 'Unable to get the server. ' . $server->faultstring;
    my $billing_id = $server->result->{'billingItem'}->{'id'};
    my $result = $billing_item_service->cancelService();
    if ($result->fault) {
        die 'Unable to cancel the server. ' . $server->faultstring;
    print Dumper($result->result);


If this article contains any error, or leaves any of your questions unanswered, please help us out by opening up a github issue.
Open an issue