4

I'm trying to add and/or delete group members using graph/api with Golang

I am able to list members, or owners for groups, but not able to add to delete members.

//---CODE--- To list member of groups this code works an intended

cred, err := azidentity.NewClientSecretCredential("7c...","16...","sj...", nil,)
auth, err := a.NewAzureIdentityAuthenticationProviderWithScopes(cred, []string{"https://graph.microsoft.com/.default"})
requestAdapter, err := msgraphsdk.NewGraphRequestAdapter(auth)
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
result, err := graphClient.Users().Get()
// get member in 1 group
graphClientGroup := msgraphsdk.NewGraphServiceClient(requestAdapter)
r2, err := graphClientGroup.GroupsById("...group-id...").Members().Get()

When I try any variation for adding including as listed in MS docs: https://learn.microsoft.com/en-us/graph/api/group-post-members?view=graph-rest-1.0&tabs=go

requestBody := msgraphsdk.New()
requestBody.SetAdditionalData(map[string]interface{}{
"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/{id}",
}
graphClient.GroupsById(&groupId).MembersById(&directoryObjectId).Post(requestBody)

This code will not compile, other variations will run but not produce new group members or return an error.

For deleting members in M365 groups I tried to run code without success such as:

graphClient.GroupsById("groupId...").MembersById("memberID...").Ref().Delete()

No errors are returned and NO member deleted from group?

Thank you, for any guidance.

BrianB
  • 41
  • 3

2 Answers2

0

As mentioned in the documentation in GitHub:

The Microsoft Graph Go SDK is currently in Community Preview and breaking changes are expecting to happen to the SDK based on community's feedback.

The error with post() has been already reported. Details here

user2250152
  • 14,658
  • 4
  • 33
  • 57
0

This issue is now fixed, as of 2022-05-31 v0.25.0

BrianB
  • 41
  • 3
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 03 '22 at 11:02