November 23, 2017


Retrieve billing items for Bare Metal servers in the account.

This script makes a single call to the getHardware() method in the SoftLayer_Account API service
and uses a object mask to get the billing items and items for each Bare Metal server in the account.

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 service
	service := services.GetAccountService(sess)

	// Declare object mask used to get information about items
	mask := "id;hostname;domain;datacenter[longName];billingItem[item]"

	// Call method getHardware() in order to retrieve billing items of each bare metal server.
	servers, err := service.Mask(mask).GetHardware()
	if err != nil {
		fmt.Printf("\n Unable to retrieve hardware servers:\n - %s\n", err)

	// Following helps to print the result en JSON format.
	for _, hardware := range servers {
		jsonFormat, jsonErr := json.MarshalIndent(hardware, "", "     ")
		if jsonErr != nil {
		fmt.Printf("\n%s", string(jsonFormat))
		// Print single separator
		fmt.Printf("\n%s", strings.Repeat("-", 120))


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