I am so proud of the Microsoft Graph Teams team 💛 It took a while, but the MS Graph Teams team released a new approach to manage Teams membership directly from a dedicated Graph teams API 😯
Background
Currently, changes made to the team’s membership had to be made to the Microsoft 365 group backing a team via the Microsoft Graph API “groups/members” / “groups/owners”. Those membership changes don’t apply immediately to the team and must be synced to the Teams service in order for newly added users to access the team. Unfortunately, the sync mechanism can take up to 24 hours according Microsoft. From my experience, it can take even longer.
The new approach
New teams Graph APIs have been introduced in order to remove the dependency on the group Graph API. Basically, it is no longer required to use group Graph APIs to manage the Teams membership since the new beta/teams/{teamId}/members API is available and it supports CRUD operations!!!
Those APIs support both, delegated and applications permissions 🥳
List all team members and owners
You can use this API to retrieve all members and owners of a TEAM within the same call 😯 That would be perfect if this API would support pagination!!! ATM, this is a known limitation! However, in many cases it might improve performance since you only need one call to retrieve owners and members of a team instead of different calls to first retrieve the group and then retrieve the owners/members. As far as I have tested, this API returns up to 100 users within one request. This is how the request to retrieve all owners and members looks:
GET https://graph.microsoft.com/beta/teams/{teamsId}/members
Check out the corresponding Microsoft Graph documentation for more information! (List all team members and owners)
Add a user
It will add users immediately (always happend during my tests) to the team or return a corresponding error code if the adding process fails. This is a great improvement since the sync delay issue between group and team will no longer be an issue as described previously. This is what the request to add new users to the team looks like:
POST https://graph.microsoft.com/beta/teams/{teamsId}/members
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": [""],
"user@odata.bind":
"https://graph.microsoft.com/beta/users/666a3fb6-d598..."
}
Check out the corresponding Microsoft Graph documentation for more information! (Add members or owners to a team)
Update a user
This API updates the user’s role in a team and is only supported on private channels. For instance, you can use this API to promote an user from member to owner:
PATCH https://graph.microsoft.com/beta/teams/{id}/channels/{id}/members/{id}
{
"@odata.type": "#microsoft.graph.aadUserConversationMember",
"roles": ["owner"]
}
Check out the corresponding Microsoft Graph documentation for more information! (Update team members or owners)
Delete a user
This API removes a user from a team 😊
DELETE https://graph.microsoft.com/beta/teams/{teamsId}/members
Check out the corresponding Microsoft Graph documentation for more information! (Delete team members or owners)
Summary
I have already had different discussions with partners and customers about the problem caused by the sync delay. This API is a big improvement in the Graph teams API. Just love it!!!
Note that this API is still in beta and seems to be still under development. During my tests, I was facing different errors like getting Bad Request when trying to delete a user from a team. However, this will be the way to go and I am very happy that Microsoft is introducing this new approach. I am really looking forward to seeing the improvements that the Microsoft Graph Teams team will be adding to those new APIs.