Contents

Using the Microsoft Graph to determine if an Office365 Group has an associated Microsoft Team

Contents

It is very easy to accidentally create an Office365 Group, for example by creating a new plan or creating new Team in Microsoft Teams; either of these (and I’m sure there are more ways) will provision an entire Office365 Group including mailbox, calendar, SharePoint team site and OneNote notebook. It doesn’t create a team unless you do it specifically in the Teams client.

You can create an Office365 Group without an associated Team, but you cannot create a Team without an Office365 Group.

Recently we wanted to determine what Office365 Groups had associated Microsoft Teams, which the data returned from the Groups APIs doesn’t seem to offer. The results returned will only tell you if it is an Office365 Group or not, that’s it.

/media/2018/06/2018-06-05_8-45-38.png

Now that the Microsoft Graph has preview access to Teams, you are given the ability to create a Team using a PUT request; we can use the same call via a GET request to determine if a Group has an associated Team. All you need to know is the Group ID.

GET https://graph.microsoft.com/beta/groups/{id}/team

How do you get the Group ID? Grab it from the Groups portion of the API. For example, the below will list out all Office365 Groups.

GET https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c+eq+'Unified') 

As Groups can be Security groups or distribution groups, this searches for Groups where the groupTypes contains Unified, which defines the group as an Office365 group.

/media/2018/06/2018-06-04_20-31-39.png

Now, if the Office365 Group has an associated Team, and you have access to that team, you will get a nice 200 Response, with a bunch of interesting data.

/media/2018/06/2018-06-04_21-47-39.png

If there is an associated Team but you do not have access to it, you will get a 403 response.

/media/2018/06/2018-06-04_21-46-06.png

And if there is no associated team at all, a 404 will be returned.

/media/2018/06/2018-06-04_21-44-371.png

This seems like the easiest/only way to determine if there is a Team associated with a Group, but is yet undocumented and still on the beta APIs so this functionality may disappear or change at any time. Additionally, you need the Groups.Read.All permissions on the app, which requires Admin consent. In addition to this, you can also batch the calls if you need to know the results of many Groups.

/media/2018/06/2018-06-04_20-31-391.png