Skip to content

Instantly share code, notes, and snippets.

@greyhoundforty
Created December 30, 2015 14:51
Show Gist options
  • Save greyhoundforty/620c55198f7e07aa1e7b to your computer and use it in GitHub Desktop.
Save greyhoundforty/620c55198f7e07aa1e7b to your computer and use it in GitHub Desktop.
Billing API REST Examples

Before we begin I find it helpful to set some environment variables so that we don't have to provide our SoftLayer user and API key in every call. In your terminal run the following, substituting in your Portal username and API key:

export SOFTLAYER_USERNAME=<username>
export SOFTLAYER_API_KEY=<apikey>

How do I find out what my next bill will be?

curl --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -sk https://api.softlayer.com/rest/v3/SoftLayer_Account/getNextInvoiceTotalAmount.json

How much has an hourly device cost me month-to-date?

 curl -sk "https://$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY@api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/<VSI_ID>/getBillingItem?objectMask=mask\[createDate,hoursUsed,hourlyRecurringFee,currentHourlyCharge\]"

How do I find a billing item from a provisioned product?

curl --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -sk \
https://api.softlayer.com/rest/v3/SoftLayer_Network_Storage/<ID>/getBillingItem

How do I cancel an item?

First get the Billing Item ID:

curl --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -sk \
https://api.softlayer.com/rest/v3/<SERVICE>/<ID>/getBillingItem

Then invoke cancelService or cancelItem

curl --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -sk https://api.softlayer.com/rest/v3/SoftLayer_Billing_Item/<BILLING_ID>/cancelService

How do I find a provisioned product from a billing item?

If you need to associate a Billing ID with the service or item it corresponds to you can use getAssociatedBillingItem or getAssociatedParent along with an Object Mask.

curl --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -sk "https://api.softlayer.com/rest/v3/SoftLayer_Billing_Item/1234321/getAssociatedParent?objectMask=mask\[id\]"

curl --user "$SOFTLAYER_USERNAME:$SOFTLAYER_API_KEY" -sk https://api.softlayer.com/rest/v3/SoftLayer_Billing_Item/1234321/getAssociatedBillingItem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment