How to Get SharePoint Online Site ID [3 Best Ways]

While working with SharePoint along with Power Apps or Power Automate, we may often require the SharePoint site ID. In my case, I removed some of the environment variables in the Power Apps solution, and then I got an error that contained an ID with the SharePoint connection. At that point, I was required to check my SharePoint site ID to solve that issue.

In this tutorial, I will explain the 3 best ways to get SharePoint Online Site ID like:

  • Get SharePoint Online Site ID Using Microsoft Graph
  • Get SharePoint Online Site ID using REST Endpoint
  • Get SharePoint Online Site ID Using PnP PowerShell

Get SharePoint Online Site ID Using Microsoft Graph

In this section, we’ll see how to get the SharePoint Online site ID using Microsoft Graph. In the image below, you can see the highlighted guid, which is nothing but an ID of the SharePoint site I gave.

get sharepoint site id

Follow the steps below to achieve this!

1. Open the Microsoft Graph with your credentials. Under SharePoint Sites -> Choose the get SharePoint site based on relative path option in the left navigation, like in the image below.

Note: On the right side you will get a sample URL “https://graph.microsoft.com/v1.0/sites/{host-name}:/{server-relative-path}”

How to get SharePoint site id using Graph API

2. In place of {host-name} provide your SharePoint domain address and in place of {server-relative-path} provide your site address like in the below.

Then click on the Run query button. You’ll see details about the SharePoint site below. The site ID is the second value of the “id” parameter.

https://graph.microsoft.com/v1.0/sites/tenantname.sharepoint.com:/sites/RetailManagementSite
Get SharePoint site ID from URL

This way you can get SharePoint site ID from the Microsoft Graph.

Get SharePoint Online Site ID using the REST Endpoint

To get the SharePoint site ID using the REST endpoint, log in to your SharePoint site, provide the URL like the one below, and hit the URL. Then, you’ll get the SharePoint site ID like in the image below.

https://{tenantname}.sharepoint.com/sites/{Sitename}/_api/site/id
Find the sharepoint Online Site ID using the REST Endpoint

This way, you can also get the SharePoint site ID from REST endpoints.

Get SharePoint Online Site ID Using PnP PowerShell

Here, we’ll see another approach to get the SharePoint online Site ID using PnP PowerShell commands.

In the image below, you can see that in the TERMINAL pane, I got the SharePoint site ID.

Get SharePoint Online Site ID Using powershell

Run the code below in VS Code or any other platform like Windows PowerShell ISE. Make sure you registered an application in Microsoft Entra ID for SharePoint, take that application ID to interact with the SharePoint site with PnP PowerShell.

Note: If you don’t know, follow this article to register an application in Microsoft Entra ID.

$SiteURL = "https://{tenant name}.sharepoint.com/sites/{site name}"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -ClientId "Your client ID" -Interactive
 
#Get the site with ID property
$Site = Get-PnPSite -Includes ID
 
#Get Site ID
Write-host -f Green "Site Collection ID:"$Site.Id 

Here, the Get-PnPSite will retrieve the provided site collection from the context. The includes parameter fetches the SharePoint site ID.

I hope you understand how to get the SharePoint Online site ID. In this article, I have explained three different approaches to getting the ID. You can follow any of the approaches.

Also, you may like:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App