Hi All,
We are trying to retrieve the list of users with the associated groups using Go SDK. However, we were unable to get the profile login details from client.User.ListUsers(). In short, we would like to get the details in the below format.
Joe@abc.com
group1
group2
Harris@abc.com
group3
group4
and so on.
Below is the code we have written for this usecase and when we run this, we get the following error.
username.Profile.login undefined (type *okta.UserProfile has no field or method login)
func main() {
// To Get Group with name
oktaurl := os.Getenv(“OKTAURL”)
oktatoken := os.Getenv(“OKTATOKEN”)
client, _ := okta.NewClient(context.Background(), okta.WithOrgUrl(oktaurl), okta.WithToken(oktatoken), okta.WithCache(false))
filter := query.NewQueryParams(query.WithFilter(“status eq “ACTIVE””))
users, _, _ := client.User.ListUsers(filter)
var userids string
var userlogin string
//Getting user names & IDs
for _, tmpuser := range users {
userids = append(userids, tmpuser.Id
userlogin = append(username, tmpuser.Profile.Login)
//fmt.Println(tmpuser.Credentials.Emails)
}
//Getting users for each group
for i, userid := range userids {
groups, resp, err := client.User.ListUserGroups(userid, nil)
if err != nil {
fmt.Println(err)
fmt.Println(resp)
}
fmt.Println("UserLogin", userlogin[i])
for _, groupname := range groups {
fmt.Println(groupname.Profile.Name)
}
}
}
Appreciate if someone can help me with this.
Many thanks in advance,
Srujan.