I'm trying to add and 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.
//---START CODE--- This code works an intended to list members. I can list members or owners
cred, err := azidentity.NewClientSecretCredential("7c...","166...","sjp...", 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-abc...").Members().Get()
//===END CODE---
But when I try any variation for adding including as listed in 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.
Deleting a member in M365 group I tried to run code without success:
graphClient.GroupsById(groupId...).MembersById(memberID...).Ref().Delete()
No errors and not able to delete member from group?
Thank you, for any guidance.