Currently we are working a new product where we need to list all Teams in an organisation regardless whether you have joined the team.
The Microsoft Graph does (at the moment of writing this article) not have an endpoint for listing all available teams. It does allow you to get a list off all Unified Group in the Beta endpoint. This can be done using using the following API call:
This call will return the first batch of groups. If there are more you will find a skip-token link in the ‘@odata.nextLink’ property. You can use this link to get the next batch until you get a result without a skip-token which means you are at the end.
Because each Team is part of a Unified Group this is a good starting point for now. Now lets assume we have a couple of hundred Unified Groups which are all potential Teams.
How to determine if a group actually is a Team?
To find out if a Group is actually a team we can make a rest call for each group like this:
This will return one of the following three responses:
- Success – Status Code 200, Team Object
- Failure – Status Code 403, AccessDenied
- Failure – Status Code 404, ItemNotFound
What’s interesting is the 403 response. If we are not a member of the Team we will receive a 403 response.
When the Unified Group is NOT a Team we receive a 404 response.
Keep in mind, it works but it doesn’t scale
Now if we wrap all these Team request in one or multiple Batch Requests we reduce the total amount of request we need to make for the required info.
It’s not the most elegant solution and it definitely doesn’t scale but it’s the only one that works at the moment of writing this article.
Just keep this in mind when developing and make sure you handle these call’s async to avoid unwanted delays.