Skip to content

Cast DirectoryObjectable to User #161

@Mattes83

Description

@Mattes83

Hi,

I am currently trying to use this library to get all members of a group.

As I did not find any documentation on how to use the results of the queries I looked into the issues and found a snippet in #79:

// response is a directory object response like for client.GroupsById("id").Members.Get(nil), where the value array is an array of directory objects
// m is the import for the models package
for _, do := range response.GetValue() {
		user := do.(m.Userable)
		upn := user.GetUserPrincipalName()
		fmt.Printf("UPN: %v\n", *upn)
	}

Should this work by now? When I try

if result, err := r.GraphServiceClient.GroupsById(objectID.String()).TransitiveMembers().Get(); err == nil {
  for _, do := range result.GetValue() {
    user := do.(models.Userable)
    upn := user.GetUserPrincipalName()
    logger.Info(*upn)
}

I get a panic because do cannot be cast to models.Userable

Best regards

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixedservice issueIssues caused by the service (metadata/behavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions