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.