November 23, 2017


GetDevicesFilteredByPrivateIP.php

GetDevicesFilteredByPrivateIP.php
<?php
/**
 * Get Items from Device list filtered by Private IP
 * using SoftLayer_Search::advancedSearch.
 *
 * Important manual pages:
 * http://sldn.softlayer.com/reference/services/SoftLayer_Search/advancedSearch
 *
 * @license <http://sldn.softlayer.com/wiki/index.php/License>
 * @author SoftLayer Technologies, Inc. <sldn@softlayer.com>
 */
require_once ('C:\softlayer-api-php-client-master\src\SoapClient.php');

/**
 * Set your SoftLayer API username and key.
 */
$apiUsername = 'set me';
$apiKey = 'set me';

$endpointUrl = 'https://api.softlayer.com/soap/v3.1/';
$serviceName = 'SoftLayer_Search';

/**
 * Set the Private IP to filter the item list.
 */
$privateIpAddress = '10.105.121.98';

/**
 * Create a client to the API service.
 */
$client = \SoftLayer\SoapClient::getClient($serviceName, null, $apiUsername, $apiKey, $endpointUrl);

/**
 * The items with the following Device types should be displayed
 * using the below filter:
 *    Bar Metal Server, Virtual Server, Firewall, Gateway Member, Netscaler,KVM/IP
 */
$filterData = 'primaryBackendIpAddress: '.$privateIpAddress .
    ' _objectType:SoftLayer_Hardware,'.
    'SoftLayer_Virtual_Guest,'.
    'SoftLayer_Network_Vlan_Firewall,'.
    'SoftLayer_Network_Application_Delivery_Controller '.
    '_sort:[fullyQualifiedDomainName:asc]';

try {

    $receipt = $client->advancedSearch($filterData);
    print_r($receipt);
} catch (Exception $e) {
    echo 'Unable to get the item list when filtering by private IP Address: ' . $e->getMessage();
}