1

Using examples in Go SDK with Username and apikey returned

{"error":"Access Denied. ","code":"SoftLayer_Exception_Public"}

package main

import (
    "fmt"

    "github.com/softlayer/softlayer-go/services"
    "github.com/softlayer/softlayer-go/session"
    "github.com/softlayer/softlayer-go/sl"
)

func main() {
        userName := "xxxx"
        apikey := "xxxx"
        sess := session.New(userName, apikey)
        sess.Debug = true
        doListAccountVMsTest(sess)
}

func doListAccountVMsTest(sess *session.Session) {
    service := services.GetAccountService(sess)

    vms, err := service.Mask("id;hostname;domain").Limit(10).GetVirtualGuests()
    if err != nil {
        fmt.Printf("Error retrieving Virtual Guests from Account: %s\n", err)
        return
    } else {
        fmt.Println("VMs under Account:")
    }

    for _, vm := range vms {
        fmt.Printf("\t[%d]%s.%s\n", *vm.Id, *vm.Hostname, *vm.Domain)
    }
}

func handleError(err error) {
    apiErr := err.(sl.Error)
    fmt.Printf(
        "Exception: %s\nMessage: %s\nHTTP Status Code: %d\n",
        apiErr.Exception,
        apiErr.Message,
        apiErr.StatusCode)
}
sheldon
  • 13
  • 4

2 Answers2

0

I didn't have issues when running your code, I recommend to check the username and apikey you are sending. See the API Access Information section in your profile https://control.softlayer.com/account/user/profile

Albert Camacho
  • 1,129
  • 1
  • 7
  • 13
  • Is it the VPN Username? IBM engineer contacted me yesterday and confirmed Username and apikey is right. I just figured out the Username he mentioned is the VPN Username.Is that right? – sheldon Dec 22 '17 at 04:31
  • No, it isn't. Looks for "API Username" and "Authentication Api Key". If you dont have one, then you need to generate it by clicking Generate in the Api Key column of table where all users are listed (Account >> Users). See https://knowledgelayer.softlayer.com/procedure/generate-api-key – Albert Camacho Dec 22 '17 at 13:23
  • Here two images: 1) UserName and ApiKey https://docs.jamcracker.com/ver3.0/sites/default/files/Authentication_Key_%26_Username.png 2) Generate an ApiKey https://www.acentera.com/assets/images/SoftlayerGenerateAPIKey.png – Albert Camacho Dec 22 '17 at 13:29
0

It is worth noting that, it is not terribly well documented on IBM cloud, and the error messages returned are not terribly clear to this fact: Sometimes the Access Denied error you receive has more to do with the fact that you do not have an upgraded IBM pay as you go account.

Worth keeping that in mind, for other users that may run into the same error message, but not know what to make of it.

Awah Teh
  • 1,217
  • 13
  • 12