November 23, 2017


Retrieve billing items of Virtual Guest servers in the account.

This script makes a single call to the getVirtualGuests() method in the SoftLayer_Account API
service and uses an object mask to get the billing items and items for each VSI server in the

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 getVirtualGuests() in order to retrieve billing items of each VSI server.
	servers, err := service.Mask(mask).GetVirtualGuests()
	if err != nil {
		fmt.Printf("\n Unable to retrieve virtual guest servers:\n - %s\n", err)

	// Following helps to print the result en JSON format.
	for _, guest := range servers {
		jsonFormat, jsonErr := json.MarshalIndent(guest, "", "     ")
		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