November 23, 2017


Get the recurring cost of all hardware servers in the account.

Get a list of servers on a SoftLayer account along with their recurring monthly costs. We can
get that by calling to the getHardware() method in the SoftLayer_Account API service, and using
object masks we'll retrieve the ID of all SoftLayer_Hardware objects. Then through a loop we will
call getObject() in SoftLayer_Hardware_Server service with a mask to retrieve the cost.
See below for more information.

Important manual pages

Author: SoftLayer Technologies, Inc. <>
package main

import (

func main() {
	// SoftLayer API username and key.
	username := "set me"
	apikey   := "set me"

	// Create a session
	sess := session.New(username, apikey)

	// Get SoftLayer_Account and service SoftLayer_Hardware_Server services.
	accountService  := services.GetAccountService(sess)
	hardwareService := services.GetHardwareServerService(sess)

	// Object mask to get the id of all SoftLayer_Hardware objects from account.
	mask := "id"

	// Object mask to get hostname, domain, cost, etc., of SoftLayer_Hardware_Server objects.
	serverMask := "id;hostname;domain;fullyQualifiedDomainName;cost"

	// Call SoftLayer_Account::getHardware() method to get all SoftLayer_Hardware objects in the account.
	hardwareList, err := accountService.Mask(mask).GetHardware()
	if err != nil {
		fmt.Printf("\n Unable to retrieve Softlayer_Hardware objects \n -%s", err)

	// For each SoftLayer_Hardware object we'll get data of SoftLayer_Hardware_Server.
	for _, hardware := range hardwareList {
		// Call SoftLayer_Hardware_Server::getObject() in order to get information based on mask.
		server, err := hardwareService.Id(*hardware.Id).Mask(serverMask).GetObject()
		if err != nil {
			fmt.Printf("\n Unable to retrieve Softlayer_Hardware_Server object\n -%s", err)

		// Following helps to print the result in JSON format.
		jsonFormat, jsonErr := json.MarshalIndent(server, "", "     ")
		if jsonErr != nil {
		fmt.Printf("\n%s", string(jsonFormat))


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