Skip to content

Instantly share code, notes, and snippets.

@sl-will
Created May 17, 2014 23:29
Show Gist options
  • Save sl-will/6868575de6dc7263968f to your computer and use it in GitHub Desktop.
Save sl-will/6868575de6dc7263968f to your computer and use it in GitHub Desktop.
SL API - REST - Basics used in product orders
# The below commands will get the basic information used in ordering products
# All calls are assumed with an env variable of $APIUSER and $APIKEY for the API username and key
# The following examples can be piped to Python for better formatting, for example:
# curl api.softlayer.com/args | python -m json.tool | less
# Related gist for integrating with scripting https://gist.github.com/sl-will/e3274c68e0e9f5eafcd1
# Get a list of all datacenter locations, optionally with the region adding "groups.name" to the object mask
# Returns array [ {"id":int, "longName":string} ]
curl -s -H 'Accept: application/json' "https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Location/getDatacenters.json?objectMask=id;longName"
# Retrieve a list of public and private network VLANs on the account, along with the router they are assigned to
# Returns array [ {"id":int, "primaryRouter": {"hostname": string}, "vlanNumber": int} ]
curl -s -H 'Accept: application/json' "https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Account/getPublicNetworkVlans.json?objectMask=id;vlanNumber;primaryRouter.hostname"
# List of all packages offered. Note that unitSize refers to the rack unit size and affects server configuration, or "null" if not applicable
# Returns array [ {"id":int, "name":string, "unitSize": int } ]
curl -s -H 'Accept: application/json' "https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Product_Package/getAllObjects.json?objectMask=id;name;unitSize"
# Verify available locations for the product package (using SoftLayer_Product_Package ID 46 as an example)
# Returns array [ {"isAvailable":int, "location": {"id":int, "name":string}} ]
curl -s -H 'Accept: application/json' "https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Product_Package/46/getAvailableLocations.json?objectMask=isAvailable;location.id;location.name"
# Verify all available and required product categories for the package (using SoftLayer_Product_Package ID 46 as an example)
# Returns array [ {"errorMessage": string, "isRequired": int, "itemCategory": {"id":int, "name":string}} ]
curl -s -H 'Accept: application/json' "https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Product_Package/46/getConfiguration.json?objectMask=errorMessage;isRequired;itemCategory.name;itemCategory.id"
# All available item prices, unsorted, along with the category ID for a given product package (using SoftLayer_Product_Package ID 46 as an example)
# Returns array [ {"categories": array [{"id":int}], "item": {"description":string, "id":int}} ]
curl -s -H 'Accept: application/json' "https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Product_Package/46/getItemPrices.json?objectMask=id;item.description;categories.id"
# Get full information for a given item, which includes restrictions and prices (using SoftLayer_Product_Item_Price ID 22384 as an example)
# Some products have multiple values (such as RHEL due to licensing) that reference the restrictions noted in capacityRestrictionType
# Returns a hash with full information, including capacityRestrictionMaximum and Minimum, setupFee, recurringFee, and includes "categories" and "items" information
curl -s -H 'Accept: application/json' "https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Product_Item_Price/22384.json?objectMask=item;categories"
# Placing an order, with order.json being a file in the same directory, formatted as JSON
# @order.json instructs curl to read from the order.json file, but JSON can also be added inline in quotes such as -d '{"json":"data"}'
curl -s -H 'Accept: application/json' "https://$APIUSER:$APIKEY@api.softlayer.com/rest/v3/SoftLayer_Product_Order/placeOrder.json -X POST -d @order.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment