Skip to content

Instantly share code, notes, and snippets.

@sudorandom
Forked from underscorephil/invoices.py
Last active December 21, 2015 04:59
Show Gist options
  • Save sudorandom/6253611 to your computer and use it in GitHub Desktop.
Save sudorandom/6253611 to your computer and use it in GitHub Desktop.
# So we can talk to the SoftLayer API:
import SoftLayer
# For nice debug output:
from pprint import pprint as pp
# Your SoftLayer API username and key.
#
# Generate an API key at the SoftLayer Customer Portal:
# https://manage.softlayer.com/Administrative/apiKeychain
api_username = ''
api_key = ''
client = SoftLayer.Client(username=api_username, api_key=api_key)
start_date = '1/01/2013 0:0:0'
end_date = '05/31/2013 23:59:59'
object_filter = {
'invoices': {
'createDate': {
'operation': 'betweenDate',
'options': [
{'name': 'startDate', 'value': [start_date]},
{'name': 'endDate', 'value': [end_date]}
]
},
},
}
object_mask = 'id, createDate, typeCode, endingBalance, account.companyName'
invoices_iter = client['SoftLayer_Account'].getInvoices(
mask=object_mask,
filter=object_filter,
chunk=3000,
iter=True)
all_invoices = [invoice for invoice in invoices_iter
if invoice['typeCode'] == 'RECURRING'
or invoice['endingBalance'] == 0]
print "Invoices between %s and %s" % (start_date, end_date)
pp(all_invoices)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment