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.
Below are my finding as per my analysis :
- 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
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".