November 23, 2017


get_invoice.rb

get_invoice.rb
# 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>
require 'softlayer_api'
require 'pp'

# Your SoftLayer API key and username.
USERNAME = 'set me'
API_KEY = 'set me'

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

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

begin
  # Retrieve the invoices for the account.
  invoices = hardware_account.object_mask(object_mask).getInvoices
  print invoices
rescue StandardError => exception
  puts "Unable to retrieve the invoices. : #{exception}"
end

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