Search code examples
phpapiibm-cloud-infrastructure

How to get the softlayer_ticket id after calling SoftLayer_billing_Item.cancelItem(...)


I use SoftLayer API PHP library to call SoftLayer_billing_Item.cancelItem(...) or SoftLayer_billing_Item.cancelService() to cancel the item. I noticed there will be SoftLayer ticket generated on the SoftLayer customer portal after the SoftLayer_billing_Item.cancelItem(...) or SoftLayer_billing_Item.cancelService() call.

The API returned result of SoftLayer_billing_Item.cancelItem(...) or SoftLayer_billing_Item.cancelService() doesn't contain the result SoftLayer_Ticket information.

How can I use API to get the SoftLayer_Ticket Id value associated with the SoftLayer_billing_Item.cancelItem(...) or SoftLayer_billing_Item.cancelService() .

Is there any same php file I can use ?


Solution

  • You can use the next objectMask in your code:

    <?php
    // Reference to the SL API client (It depends on your path installation) 
    require_once ('C:\softlayer-api-php-client-master\src\SoapClient.php');
    require_once ('C:\softlayer-api-php-client-master\src\Common\ObjectMask.php');
    
    // Set these values with your valid information.
    $username = 'set me';
    $apiKey = 'set me';
    
    $service = 'SoftLayer_Billing_Item';
    
    // Set your billing item Id.
    $billingItemId = 7883593;
    
    // The client instantiation.
    $client = \SoftLayer\SoapClient::getClient($service, $billingItemId, $username, $apiKey);
    
    // The next lines belong to the creation of an object mask that retrieves aditional data
    // contained in the objects retrieved.
    $objectMask = new \SoftLayer\Common\ObjectMask();
    $objectMask->cancellationRequests->ticket;
    $client->setObjectMask($objectMask);
    
    try 
    {
        // Retrieving the configuration options for a SoftLayer_Hardware object.
        $cancellation_request = $client->getCancellationRequests();
        print_r($cancellation_request);
    } 
    catch (\Exception $e) 
    {
        // Displaying if an error happened.
        die('Script failed, review the next message for further details: ' . $e->getMessage());
    }
    

    You can use the same objectMask in the same way for methods such as SoftLayer_Account::getLastCanceledBillingItem or SoftLayer::getLastCancelledServerBillingItem