Search code examples
phpapiibm-cloud-infrastructure

Softlayer API to pull all invoices


I was successful in pulling an excel sheet from SoftLayer's API using PHP via

$client = \SoftLayer\SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
$invoice = $client->getNextInvoiceExcel();

I write it to a location where it goes on a webserver and executes with a crontab.

I am trying to find out if I can also pull an Excel sheet for previous months. Through the Softlayer Web Portal, I am able to pull this information via manually selecting an invoice and downloading it to Excel. The problem is we manage several accounts and we'd like to automate using an id and api key to pull their previous month's invoices.

Right now I can only list them using:

$client = \SoftLayer\SoapClient::getClient('SoftLayer_Account', null, $apiUsername, $apiKey);
$user_bill = $client->getOpenRecurringInvoices();

print_r($user_bill);

Thank you for your help.


Solution

  • Using SLAPI methods, it may help you: SoftLayer_Billing_Invoice/getExcel.

    First, you can get the invoices with: SoftLayer_Account::getOpenRecurringInvoices

    And then, with invoice_ids displayed in the last request, you can execute (Rest example):

    https://[username]:[apikey]@api.softlayer.com/rest/v3/SoftLayer_Billing_Invoice/[invoice_id]/getExcel
    
    Method: GET
    

    I hope it help you.