November 23, 2017


Retrieve the subnets for a VLAN

Retrieve all the subnets for a determinate VLAN associated with a SoftLayer customer account
We do this with a call to the getSubnets() method in the SoftLayer_Network_Vlan API service.
See below for more details.

Important manual pages:

Author: SoftLayer Technologies, Inc. <>

package main

import (

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

	// Vlan id you wish to get its subnets
	vlanId := 1054267

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

	// Get SoftLayer_Network_Vlan service
	service := services.GetNetworkVlanService(sess)

	// Object-Mask to get specific subnet's information
	mask := "id;networkIdentifier;cidr;subnetType;totalIpAddresses;usableIpAddressCount"

	// Call to getSubnets() in order to retrieve all vlan's subnets.
	subnets, err := service.Id(vlanId).Mask(mask).GetSubnets()
	if err != nil {
		fmt.Printf("\n Unable to get Vlan's subnets:\n - %s\n", err)

	// Following helps to print the result in json format.
	for _,subnet := range subnets {
		jsonFormat, jsonErr := json.Marshal(subnet)
		if jsonErr != nil {


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