How can I get the siteId of the current site with Microsoft Graph API?
On classic sites using spPageContextInfo
:
(location.host + "," + _spPageContextInfo.siteId + "," + _spPageContextInfo.webId).replace(/[\{\}]/g, "")
Try this: https://graph.microsoft.com/v1.0/sites/{hostname}:/sites/{path}?$select=id
For example:
https://graph.microsoft.com/v1.0/sites/cie493742.sharepoint.com:/sites/Contoso/Operations/Manufacturing?$select=id
(this one you can try on the Graph Explorer.
What you get back in the id is in this format:
{hostname},{spsite.id},{spweb.id}
For more info here is the link to the docs: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/site_get
Another way you can get the Site-id by below Graph Http Get API.
https://graph.microsoft.com/v1.0/sites
You don't need to do a Graph API call to get the siteId of the current site. It is available in the PageContext.
In the main class of your webpart you can find it at:
this.context.pageContext.site.id