How do I get M365 groups associated with a Sharepoint site?

Adam 41 Reputation points
2022-05-04T14:55:50.233+00:00

I am trying to get a list of the M365 groups that are associated with a particular Sharepoint Site.
A really crude way to do it would be to call /sites and /groups and match up names by string but this wouldnt work if multiple groups are assigned to a site.
What is the proper way to do this through the Graph API?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,504 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,560 questions
0 comments No comments
{count} votes

Accepted answer
  1. JanardhanaVedham-MSFT 3,536 Reputation points
    2022-05-05T00:03:51.85+00:00

    Hi @Anonymous ,

    Please note that Microsoft 365 group can be associated with a SharePoint team site and as you can see in this documentation, a SharePoint team site can only be connected to a single Microsoft 365 group . Hence a SharePoint site can't be associated with more than one M365 groups.

    198920-image.png

    Below are my finding as per my analysis :

    1. By default mailNickname is used for the site URL. So if the site URL is https://tenant.sharepoint.com/sites/MyTeamSite then GET https://graph.microsoft.com/v1.0/groups?$filter=mailNickname eq 'MyTeamSite'&$select=id,mailNickname Graph API endpoint will give you the Group ID and Group name. But this option can only be considered when there is no change in the SharePoint Site URL and also the site URL should n't be changed in future. But this approach is not recomended since the SharePoint site URL can be changed by SharePoint admins anytime if needed.

    2.As an alternative solution option, you consider using below SharePoint REST API to get associated/connected group ID of a SharePoint team site. You use GroupId and GroupAlias (i.e, group name) from this API response.

    https://{siteurl}/_api/web/allproperties  
    

    Example : https://tenant.sharepoint.com/sites/MyGroupTestURLChanged/\_api/web/allproperties

    199041-image.png
    3. As currently there no Graph API available to get associated/connected group ID of a SharePoint team site, you can submit this feature request idea using this support link, which will be monitored by Microsoft team and make the enhancements to Microsoft Graph APIs. I will also upvote for you.

    If the answer is helpful to you, please click "Accept Answer" and kindly upvote it. If you have additional questions about this answer, please click "Comment".

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Vasil Michev 94,521 Reputation points MVP
    2022-05-04T16:35:17.807+00:00

    You can get the associated M365 group by looking at the value of the GroupID property for each site. There's a ready to use script here: https://office365itpros.com/2019/08/15/reporting-group-enabled-sharepoint-online-sites/