Microsoft Graph typically requires us to use the Group ID when working with O365 groups and modern sites. But Group ID can be tricky to find since it is rarely displayed. Here are some ways I found to quickly get hold of it during when experimenting with MS Graph:
1. The group ID is made available on our trusty old friend
_spPageContextInfoin the group’s SharePoint site. Knowing this we can easily find it by going to the site and type
_spPageContextInfo.groupIdin the JS console. _spPageContextInfo is however not available on modern pages, but you can go to a page that is not modern such as Site Settings to find it.
2. Using Graph Explorer we can query for the group. By default mailNickname is used for the site URL. So if the site URL is
https://tenant.sharepoint.com/sites/MyTeamSitethen GET
https://graph.microsoft.com/v1.0/groups?$filter=mailNickname eq 'MyTeamSite'&$select=idwill give you the Group ID. Note that mailNickname is not guaranteed to be the same as the site URL, for example if you have changed the site URL.
3. Group ID is also hidden deep in the page source of modern sites. To find it you can view the page source (CTRL+U) and search for
spPageContextInfo. Triple click the paragraph you found to select it, copy the paragraph to the clipboard, open the JS console and paste it between two brackets { CTRL+V } and press enter. Now you can easily inspect the object and find the group id.
4. We can actually get to the page context object on modern pages too, but it is hidden deep down:
window.spModuleLoader._bundledComponents["b6917cb1-93a0-4b97-a84d-7cf49975d4ec"].PageManager._instance.pageContext.legacyPageContext.groupId(FYI: The GUID here refers to the web scoped feature for “modern” pages.). I made a bookmarklet to make it easier to access:
javascript:void%20function(){alert(window.spModuleLoader._bundledComponents[%22b6917cb1-93a0-4b97-a84d-7cf49975d4ec%22].PageManager._instance.pageContext.legacyPageContext.groupId)}();