sites: getAllSites
Article
10/27/2023
9 contributors
Feedback
In this article
List sites across geographies in an organization. This API can also be used to enumerate all sites in a non-multi-geo tenant.
For more information, 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
Choose the permission or permissions marked as least privileged for this API. Use a higher privileged permission or permissions only if your app requires it . For details about delegated and application permissions, see Permission types . To learn more about these permissions, see the permissions reference .
Permission type
Least privileged permissions
Higher privileged permissions
Delegated (work or school account)
Not supported.
Not supported.
Delegated (personal Microsoft account)
Not supported.
Not supported.
Application
Sites.Read.All
Sites.ReadWrite.All
HTTP request
GET /sites/getAllSites
Examples
Example 1: Initial request
Request
GET https://graph.microsoft.com/v1.0/sites/getAllSites
// 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.GetAllSites.GetAsGetAllSitesGetResponseAsync();
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)
getAllSites, err := graphClient.Sites().GetAllSites().GetAsGetAllSitesGetResponse(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);
var result = graphClient.sites().getAllSites().get();
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 getAllSites = await client.api('/sites/getAllSites')
.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()->getAllSites()->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_all_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-apc.sharepoint.com,bf6fb551-d508-4946-a439-b2a6154fc1d9,65a04b8b-1f44-442b-a1fc-9e5852fb946c",
"name": "Root Site",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostName": "contoso-apc.sharepoint.com",
"dataLocationCode": "APC",
"root": { }
},
"webUrl": "https://contoso-apc.sharepoint.com"
},
{
"id": "contoso-apc.sharepoint.com,d9ecf079-9b13-4376-ac5d-f242dda55626,746dbcc1-fa2b-4120-b657-2670bae5bb6f",
"name": "Site A",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostName": "contoso-apc.sharepoint.com"
},
"webUrl": "https://contoso-apc.sharepoint.com/sites/siteA"
},
{
"id": "contoso-apc.sharepoint.com,fd1a778f-263e-4c43-acdf-d5c2519d80eb,c06016db-dfec-4f79-83a1-09c6dbfd7022",
"name": "Site B",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostName": "contoso-apc.sharepoint.com"
},
"webUrl": "https://contoso-apc.sharepoint.com/sites/siteB"
}
],
"@odata.nextLink": "https://graph.microsoft.com/v1.0/sites/oneDrive.getAllSites?$skiptoken=U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ"
}
This response includes the first page of enumerated sites, and the @odata.nextLink property indicates that there are more items available in the current set of items. Your app should continue to request the URL value of @odata.nextLink until all pages of items are retrieved.
Example 2: Subsequent request
Request
GET /sites/getAllSites?$skiptoken=U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ
// 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
// Note: The URI string parameter used with WithUrl() can be retrieved using the OdataNextLink or OdataDeltaLink property from a response object
var result = await graphClient.Sites.GetAllSites.WithUrl("https://graph.microsoft.com/v1.0/sites/getAllSites?$skiptoken=U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ").GetAsGetAllSitesGetResponseAsync();
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)
requestSkiptoken := "U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ"
requestParameters := &graphsites.SitesGetAllSites()RequestBuilderGetQueryParameters{
Skiptoken: &requestSkiptoken,
}
configuration := &graphsites.SitesGetAllSites()RequestBuilderGetRequestConfiguration{
QueryParameters: requestParameters,
}
getAllSites, err := graphClient.Sites().GetAllSites().GetAsGetAllSitesGetResponse(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);
var result = graphClient.sites().getAllSites().get(requestConfiguration -> {
requestConfiguration.queryParameters.skiptoken = "U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ";
});
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 getAllSites = await client.api('/sites/getAllSites')
.skiptoken('U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ')
.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\GetAllSites\GetAllSitesRequestBuilderGetRequestConfiguration;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestConfiguration = new GetAllSitesRequestBuilderGetRequestConfiguration();
$queryParameters = GetAllSitesRequestBuilderGetRequestConfiguration::createQueryParameters();
$queryParameters->skiptoken = "U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ";
$requestConfiguration->queryParameters = $queryParameters;
$result = $graphServiceClient->sites()->getAllSites()->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.getAllSites.get_all_sites_request_builder import GetAllSitesRequestBuilder
graph_client = GraphServiceClient(credentials, scopes)
query_params = GetAllSitesRequestBuilder.GetAllSitesRequestBuilderGetQueryParameters(
skiptoken = "U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ",
)
request_configuration = GetAllSitesRequestBuilder.GetAllSitesRequestBuilderGetRequestConfiguration(
query_parameters = query_params,
)
result = await graph_client.sites.get_all_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-nam.sharepoint.com,bf6fb551-d508-4946-a439-b2a6154fc1d9,65a04b8b-1f44-442b-a1fc-9e5852fb946c",
"name": "Root Site",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostName": "contoso-nam.sharepoint.com",
"dataLocationCode": "NAM",
"root": { }
},
"webUrl": "https://contoso-nam.sharepoint.com"
},
{
"id": "contoso-nam.sharepoint.com,d9ecf079-9b13-4376-ac5d-f242dda55626,746dbcc1-fa2b-4120-b657-2670bae5bb6f",
"name": "Site A",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostName": "contoso-nam.sharepoint.com"
},
"webUrl": "https://contoso-nam.sharepoint.com/sites/siteA"
},
{
"id": "contoso-nam.sharepoint.com,fd1a778f-263e-4c43-acdf-d5c2519d80eb,c06016db-dfec-4f79-83a1-09c6dbfd7022",
"name": "Site B",
"isPersonalSite": false,
"root": { },
"siteCollection": {
"hostName": "contoso-nam.sharepoint.com"
},
"webUrl": "https://contoso-nam.sharepoint.com/sites/siteB"
}
],
"@odata.nextLink": "https://graph.microsoft.com/v1.0/sites/oneDrive.getAllSites?$skiptoken=U1BHZW9EYXRhTG9jYXRpb25Db2RlYU5BTQ"
}