create_portal_user.go
create_portal_user.go
/*
Create Portal User.
This script will create a new portal user based in the values set into a SoftLayer_User_Customer
template object and then it will pass to SoftLayer_User_Customer::createObject method.
Check below references for more details.
Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_User_Customer/createObject
http://sldn.softlayer.com/reference/datatypes/SoftLayer_User_Customer
@License: http://sldn.softlayer.com/article/License
@Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
*/
package main
import (
"fmt"
"encoding/json"
"github.com/softlayer/softlayer-go/datatypes"
"github.com/softlayer/softlayer-go/sl"
"github.com/softlayer/softlayer-go/session"
"github.com/softlayer/softlayer-go/services"
)
func main() {
// SoftLayer API username and key
username := "set me"
apikey := "set me"
// Build the skeleton of new user like below 6660647
userTemplate := datatypes.User_Customer {
Username : sl.String("user02"),
FirstName : sl.String("firstname"),
LastName : sl.String("lastname"),
Email : sl.String("user01_mail@softlayer.local"),
Address1 : sl.String("Address 01"),
CompanyName : sl.String("Some Company"),
Country : sl.String("US"),
City : sl.String("Dallas"),
State : sl.String("TX"),
OfficePhone : sl.String("4422335"),
PostalCode : sl.String("2500"),
TimezoneId : sl.Int(114),
UserStatusId : sl.Int(1001),
}
// Set the password of user
password := "Password!123"
// Create SoftLayer API session
sess := session.New(username, apikey)
// Get SoftLayer_User_Customer service
service := services.GetUserCustomerService(sess)
portalUser, err := service.CreateObject(&userTemplate, &password, &password)
if err != nil {
fmt.Printf("\n Unable to create new portal user:\n - %s\n", err)
return
}
// Following helps to print the result in json format.
jsonFormat, jsonErr := json.MarshalIndent(portalUser,""," ")
if jsonErr != nil {
fmt.Println(jsonErr)
return
}
fmt.Println(string(jsonFormat))
}