November 23, 2017


get_invoice.py

get_invoice.py
"""
Retrieve the invoice information.

This script makes a single call to the getInvoices() method in the
SoftLayer_Account API service and uses a object mask to get more
information about the invoices.

Important manual pages
http://sldn.softlayer.com/reference/services/SoftLayer_Account
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getInvoices
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Billing_Invoice

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer

"""
Client configuration
Your SoftLayer API username and key.
"""
USERNAME = 'set me'
API_KEY = 'set me'

# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountService = client['SoftLayer_Account']

# Declaring the object mask to get information about the invoices.
objectMask = "mask[payment,amount,invoiceTotalOneTimeAmount,invoiceTotalRecurringAmount,invoiceTotalOneTimeTaxAmount,invoiceTotalRecurringTaxAmount]"

try:
    # Retrieve the invoices for the account.
    invoices = accountService.getInvoices(mask=objectMask)
    print(invoices)
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to retrieve the invoices. " % (e.faultCode, e.faultString))
    exit(1)

Feedback?

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