We are ushering in a new era at SoftLayer with the release of the SoftLayer API. The API opens endless possibilities for our customers to integrate SoftLayer specific functionality into their corporate infrastructure and / or software products. With the API, you can provide datacenter specific control for your server or custom management of SoftLayer services to your customer base. For server resellers, this allows unbranded SoftLayer functionality to their customers via integration into their current customer portal. The API utilizes SOAP or XML-RPC for a communication protocol, by using a non-language specific protocol like SOAP or XML-RPC integration can be made with most current programming languages.
With the growing adoption of PHP on the web, I am going to show you a quick example utilizing PHP 5 with SOAP support enabled. For this example, we are going to pull the list of servers associated with an account and format the results into an html table. This should provide a brief overview to how easy integration into a system utilizing PHP could be.
Let start by defining a few variables we will use which are commented below:
// Enables or disables the WSDL caching feature
ini_set("soap.wsdl_cache_enabled", "0");
// Your API Access key, that you generated in the customer portal
define('AUTH_KEY',
'000000000000000000000000000000000000000000000000000');
// Your Customer Portal Username
define('AUTH_USER','SL00000');
// Where our SOAP server is located
define('SOAP_SERVER_LOCATION ',
'https://api.service.softlayer.com/soap/v1/SL-Service.html');
?>
Our first step after setting our configuration options is to create the SOAP client connection:
$client = new SoapClient(null, array('location' => SOAP_SERVER_LOCATION,
'uri' => SOAP_SERVER_LOCATION) );
?>
Next we will setup a few variables to be used with a try / catch statement. The try / catch statement will perform the call to the SOAP server:
# Did our SOAP call complete?
$bolResult = false;
# What was the returned error message
$strErrorMessage = "";
# Lets store our results in an array
$arrResult = array();
try {
$arrResult = $client->__call("getServerList", array() ,null ,
new SoapHeader('myUrn', 'authenticate',
array(AUTH_USER, AUTH_KEY) ) );
$bolResult = true
} catch( SoapFault $e ) {
$strErrorMessage = $e->getMessage();
}
?>
You might have noticed that we created a SOAP header that was placed in the call. This was used to pass the login credentials for authentication on the server.
At this point, there should be a response or an error message. Next we will do some basic formatting for the web to show the results.
if($bolResult){
echo ''."\
";
\
";
if(count($arrResult)){
foreach($arrResult as $arrServer){
echo ''; \
";
echo ''.$arrServer['ID'].' ';
echo ''.$arrServer['SERVERNAME'].' ';
echo ''.$arrServer['PUBLIC_IP_ADDRESS'].' ';
echo ''.$arrServer['PRIVATE_IP_ADDRESS'].' ';
echo ''.$arrServer['MGMT_IP_ADDRESS'].' ';
echo "
}
} else {
echo " ";No Servers Found!
}
echo "
}else{
echo "There was an error with your SOAP call
\
";
echo "Error Response:
\
";
echo $strErrorMessage."
\
";
}
echo "Done!
\
";
?>
This sums up how to make a request using PHP 5 with SOAP support enabled. Using the SOAP or XML-RPC protocol make the API easy to integrate into most languages, but makes it difficult to cover every language in an example. For that reason, I have included some raw SOAP requests below. If you can send a RAW HTTP POST request to our SOAP server in the format below, chances are your language can integrate into the SoftLayer API.
Example SOAP Request (no parameters)
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
Example SOAP Request (with parameters)
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
Additional Resources:
http://www.php.net/manual/en/ref.soap.php
http://en.wikipedia.org/wiki/SOAP
http://www.xmlrpc.com/