How to find {sitesId} to pass to MS Graph API call?


SharePoint related MS Graph API call requires {sitesid}, for example for the following API call we need {sitesId}

Create permission – Microsoft Graph v1.0 | Microsoft Docs

POST /sites/{sitesId}/permissions


Login to your SharePoint site. Go to Graph Explorer,, enter the following request call, assuming tenant as m365x162783 and site as Test1.$select=id

You will get a response something like the following.

    "@odata.context": "$metadata#sites(id)/$entity",
    "id": ",2e0ad342-19b2-4116-b6a5-2dc4867cb498,0efde304-9646-43d8-8eee-5b1a55ab17f1"

What you get back in the id is in this format:

The Graph Explorer request-response


This is a simple way to get this sites-id information for any future MS Graph API calls if you may want to explore using PostMan or RESTClient.

However, if you want to make this call in your code you will need an access token and make a similar call as above to get the information.

$tenantPrefix = "m365x162783";
$clientId = "Client-ID";
$clientSecret = "Client-Secret";
$tenantName = $tenantPrefix +"";
$tenantDomain = $tenantPrefix +"";

#Provide site url
$sitePath = ""
$siteName = $sitePath.Split("/")[4]

# use splatting
$ReqTokenBody = @{
Grant_Type    = "client_credentials"
Scope         = ""
client_Id     = $clientID
Client_Secret = $clientSecret
$TokenResponse = Invoke-RestMethod -Uri "$TenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody

$apiUrl = ''+ $tenantDomain +':/sites/'+ $siteName +'?$select=id,displayName'
try {
  $spoResult = Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri  $apiUrl -Method Get 
  Write-Host "Site:" $spoResult.displayName
catch {
  Write-Output "Failed to enumerate the site"
  Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
  Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription 

# NOTE THE SITES-ID is passed for the next call.
$apiUrl = ''+ $ +'/permissions'

About Pankaj

I am a Developer and my linked profile is
This entry was posted in MS Graph, SharePoint. Bookmark the permalink.

3 Responses to How to find {sitesId} to pass to MS Graph API call?

  1. $apiUrl = ‘’+ $ +’/permissions’
    when i have used this i am getting the 403 error

    • Pankaj says:

      This article was about finding site-id value. The permission call was an example, you are getting 403 because that call requires an access token.

  2. BA1968 says:

    Thanks for the post. I have a SharePoint site in the EMEA region and used (for example) to get the sitesID. However, when I try to assign permissions, I get an “Item not found” error for this EMEA SharePoint site. My “North America” sites do not generate an error.

    Is there a limitation to the Graph API for EMEA sites?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s