List sites
Article
11/18/2023
13 contributors
Feedback
In this article
Namespace: microsoft.graph
List all available sites in an organization.
Specific filter criteria and query options are also supported and described below:
Filter statement
Select statement
Description
siteCollection/root ne null
siteCollection,webUrl
Lists all root-level site collections in the organization. Useful for discovering the home site for each geography.
In addition, you can use a $search query against the /sites
collection to find sites matching given keywords.
If you want to list all sites across all geographies, refer to getAllSites .
For more guidance about building applications that use site discovery for scanning purposes, see Best practices for discovering files and detecting changes at scale .
This API is available in the following national cloud deployments .
Global service
US Government L4
US Government L5 (DOD)
China operated by 21Vianet
✅
✅
✅
✅
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
List all site collections
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Not supported.
Delegated (personal Microsoft account)
Not supported.
Application
Sites.Read.All, Sites.ReadWrite.All
Discover the home site for each geography
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Sites.Read.All, Sites.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
Sites.Read.All, Sites.ReadWrite.All
HTTP request
To list all available sites in an organization:
GET /sites
To list all root-level site collections in an organization:
GET /sites?$filter=siteCollection/root ne null
Examples
Example 1: List sites using query parameters
Request
GET https://graph.microsoft.com/v1.0/sites?$select=siteCollection,webUrl&$filter=siteCollection/root%20ne%20null
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Sites.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Select = new string []{ "siteCollection","webUrl" };
requestConfiguration.QueryParameters.Filter = "siteCollection/root ne null";
});
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc sites list --filter "siteCollection/root ne null" --select "siteCollection,webUrl"
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphsites "github.com/microsoftgraph/msgraph-sdk-go/sites"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestFilter := "siteCollection/root ne null"
requestParameters := &graphsites.SitesRequestBuilderGetQueryParameters{
Select: [] string {"siteCollection","webUrl"},
Filter: &requestFilter,
}
configuration := &graphsites.SitesRequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
sites, err := graphClient.Sites().Get(context.Background(), configuration)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SiteCollectionResponse result = graphClient.sites().get(requestConfiguration -> {
requestConfiguration.queryParameters.select = new String []{"siteCollection", "webUrl"};
requestConfiguration.queryParameters.filter = "siteCollection/root ne null";
});
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
let sites = await client.api('/sites')
.filter('siteCollection/root ne null')
.select('siteCollection,webUrl')
.get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Sites\SitesRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new SitesRequestBuilderGetRequestConfiguration();
$queryParameters = SitesRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->select = ["siteCollection","webUrl"];
$queryParameters->filter = "siteCollection/root ne null";
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->sites()->get($requestConfiguration)->wait();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
from msgraph import GraphServiceClient
from msgraph.generated.sites.sites_request_builder import SitesRequestBuilder
graph_client = GraphServiceClient(credentials, scopes)
query_params = SitesRequestBuilder.SitesRequestBuilderGetQueryParameters(
select = ["siteCollection","webUrl"],
filter = "siteCollection/root ne null",
)
request_configuration = SitesRequestBuilder.SitesRequestBuilderGetRequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.sites.get(request_configuration = request_configuration)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"id": "contoso.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,712a596e-90a1-49e3-9b48-bfa80bee8740",
"name": "Contoso USA",
"root": { },
"siteCollection": {
"hostname": "contoso.sharepoint.com",
"dataLocationCode": "NAM",
"root": { }
},
"webUrl": "https://contoso.sharepoint.com"
},
{
"id": "contoso-jpn.sharepoint.com,da60e844-ba1d-49bc-b4d4-d5e36bae9019,0271110f-634f-4300-a841-3a8a2e851851",
"name": "Contoso Japan",
"root": { },
"siteCollection": {
"hostname": "contoso-jp.sharepoint.com",
"dataLocationCode": "JPN",
"root": { }
},
"webUrl": "https://contoso-jp.sharepoint.com"
}
]
}
Example 2: List all sites
Request
GET https://graph.microsoft.com/v1.0/sites
// Code snippets are only available for the latest version. Current version is 5.x
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Sites.GetAsync();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
sites, err := graphClient.Sites().Get(context.Background(), nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SiteCollectionResponse result = graphClient.sites().get();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
use Microsoft\Graph\GraphServiceClient;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$result = $graphServiceClient->sites()->get()->wait();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
from msgraph import GraphServiceClient
graph_client = GraphServiceClient(credentials, scopes)
result = await graph_client.sites.get()
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
HTTP/1.1 200 OK
Content-type: application/json
{
"value": [
{
"id": "contoso.sharepoint.com,bf6fb551-d508-4946-a439-b2a6154fc1d9,65a04b8b-1f44-442b-a1fc-9e5852fb946c",
"name": "Root Site",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostname": "contoso.sharepoint.com",
"dataLocationCode": "NAM",
"root": { }
},
"webUrl": "https://contoso.sharepoint.com"
},
{
"id": "contoso.sharepoint.com,d9ecf079-9b13-4376-ac5d-f242dda55626,746dbcc1-fa2b-4120-b657-2670bae5bb6f",
"name": "Site A",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostname": "contoso.sharepoint.com"
},
"webUrl": "https://contoso.sharepoint.com/sites/siteA"
},
{
"id": "contoso.sharepoint.com,fd1a778f-263e-4c43-acdf-d5c2519d80eb,c06016db-dfec-4f79-83a1-09c6dbfd7022",
"name": "Site B",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostname": "contoso.sharepoint.com"
},
"webUrl": "https://contoso.sharepoint.com/sites/siteB"
}
]
}