'Add/delete members to M365 groups using MS Graph API with Golang

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://docs.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.



Solution 1:[1]

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

Solution 2:[2]

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

Solution 3:[3]

This part is a bit hidden in the documentation, but the easiest way to add mutations written in JavaScript is the makeExtendSchemaPlugin.

Here you can define type definitions in SDL and implement resolvers in JS.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2250152
Solution 2 BrianB
Solution 3 Herku