November 23, 2017
Get item prices information

This script retrieves information of prices from a package. It retrieves the item description,
location conflicts, pricing location group and item conflicts

Important manual pages:

@Author: SoftLayer Technologies, Inc. <>
# So we can talk to the SoftLayer API:
import SoftLayer
from prettytable import PrettyTable
# Your SoftLayer API username and key.
API_USERNAME = 'set me'
API_KEY = 'set me'
# Declare the image template id
packageId = 265
# Create a client instance
client = SoftLayer.Client(username=API_USERNAME, api_key=API_KEY)
# Declare an object mask to get location conflicts
objectMask = 'mask[pricingLocationGroup[locations],item[locationConflicts, conflicts]]'

    locations = client['SoftLayer_Product_Package'].getRegions(id=packageId)
    items = client['SoftLayer_Product_Package'].getItems(id=packageId)
    print('*****  AVAILABLE LOCATIONS  *****')
    for location in locations:
        print('Id: %s,  Location: %s' % (location['location']['location']['id'], location['location']['location']['longName']))
    itemPrices = client['SoftLayer_Product_Package'].getItemPrices(id=packageId, mask=objectMask)
    x = PrettyTable(["Price Id", "Item Id", "Description", "Datacenter conflicts", "Pricing Location", 'Item conflicts'])
    x.align["Price Id"] = "l"  # Left align city names
    x.padding_width = 1
    for price in itemPrices:
        dcConflicts = ''
        pricingLocation = ''
        itemConflicts = ''
        # Get location conflicts
        if  len(price['item']['locationConflicts']) > 0:
            for locationConflicts in price['item']['locationConflicts']:
                for location in locations:
                    if locationConflicts['resourceTableId'] == location['location']['location']['id']:
                        dcConflicts = dcConflicts + ' ' + location['location']['location']['longName']
            dcConflicts = "None"
        # Get Pricing location
        if 'pricingLocationGroup' in price:
            for priceLocation in price['pricingLocationGroup']['locations']:
                pricingLocation = pricingLocation + ' ' + priceLocation['longName']
            pricingLocation = 'Standard price'
        # Get item conflicts
        if len(price['item']['conflicts']) > 0:
            for conflict in price['item']['conflicts']:
                itemConflicts = itemConflicts + ' ' + str(conflict['resourceTableId'])
            conflictItems = 'None'
        x.add_row([price['id'], price['item']['id'], price['item']['description'], dcConflicts, pricingLocation, itemConflicts])
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to get item prices faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))


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