Search code examples
ibm-cloud-infrastructure

Softlayer golang object mask not working


I have the following piece of gloang code. ALthough this works I cannot see the relational property primaryRouter in the result.

package main

import (
"fmt"
"github.com/softlayer/softlayer-go/services"
"github.com/softlayer/softlayer-go/session"
"encoding/json"
)

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)

// Object-Mask to get specific Vlan's information
mask := "id;primaryRouter"

// Call to getNetworkVlans in order to retrieve vlans according to filter.
result, err := service.Mask(mask).GetNetworkVlans()
if err != nil {
    fmt.Printf("\n Unable to retrieve vlans:\n - %s\n", err)
    return
}

// Following helps to print the result in json format.
jsonFormat, jsonErr := json.MarshalIndent(result,"","     ")
if jsonErr != nil {
    fmt.Println(jsonErr)
    return
}
fmt.Println(string(jsonFormat))
}

Here is the output:

[  
     {
          "accountId": XXXXX,
          "id": 2412297,
          "modifyDate": "2018-08-15T11:32:31-08:00",
          "primarySubnetId": 1812739,
          "vlanNumber": 1416
     },
     {
          "accountId": XXXXXX,
          "id": 2412295,
          "modifyDate": "2018-08-15T11:32:27-08:00",
          "primarySubnetId": 1732951,
          "vlanNumber": 1246
     }
]

When I hit the same rest API I get the correct output:

https://{{sluser}}:{{slkey}}@api.softlayer.com/rest/v3.1/SoftLayer_Account/getNetworkVlans?objectMask=id;primaryRouter


Solution

  • Try in your code with the REST endpoint, like this example:

    username := "set-me"
    apikey   := "set-me"
    endpoint := "https://api.softlayer.com/rest/v3"
    
    // Create a session
    sess := session.New(username, apikey, endpoint)
    

    For more references you can see the followings links:

    Unable to get itemCategory info from call GetConfiguration when called from golang

    Mask and filter are not working when using the SoftLayer API