Discover root SharePoint sites across all geo with the Graph API

Sites API

The current Sites API can retrieve all sites in default geo of your organization.

GET /v1.0/sites?$filter=siteCollection/root ne null

You can fetch hostnames for the multi geo tenant but you can't retrieve the root sites for all these hostnames in the Graph API.

GetAllSites endpoint

You can enumerate root sites across all the geopgraphies in your tenant by calling

GET /v1.0/sites/getAllSites

The endpoint supports only the application permission Sites.Read.All.

OData query parameters

Which OData query parameters are supported? Allmost all except $expand.

Count

Includes the count of the items in the response string.

GET /v1.0/sites/getAllSites?$count=true

Select

Returns only selected property

GET /v1.0/sites/getAllSites?$select=id,displayName,webUrl

Filtering

All properties support filtering

id

The id property supports eq, ne, contains, endsWith, in and not query operator.

GET /v1.0/sites/getAllSites?$filter=id eq '4wrvkx.sharepoint.com,901eb771-4f0c-43f6-957e-7aeb1b91d8dc,4f047eeb-b78b-4965-be98-13024ebd232c'
GET /v1.0/sites/getAllSites?$filter=id ne '4wrvkx.sharepoint.com,901eb771-4f0c-43f6-957e-7aeb1b91d8dc,4f047eeb-b78b-4965-be98-13024ebd232c'
GET /v1.0/sites/getAllSites?$filter=contains(id,'901eb771-4f0c-43f6-957e-7aeb1b91d8dc')
GET /v1.0/sites/getAllSites?$filter=startsWith(id,'4wrvkx.sharepoint.com,901eb771-4f0c-43f6-957e-7aeb1b91d8dc')
GET /v1.0/sites/getAllSites?$filter=endsWith(id,'901eb771-4f0c-43f6-957e-7aeb1b91d8dc,4f047eeb-b78b-4965-be98-13024ebd232c')
GET /v1.0/sites/getAllSites?$filter=id in ('4wrvkx.sharepoint.com,901eb771-4f0c-43f6-957e-7aeb1b91d8dc,4f047eeb-b78b-4965-be98-13024ebd232c','4wrvkx-my.sharepoint.com,722129ef-a772-4461-972c-5b9ab897f3d6,b7c975e9-cb22-4f66-8652-73e63e470af8')
GET /v1.0/sites/getAllSites?$filter=not(id in ('4wrvkx.sharepoint.com,901eb771-4f0c-43f6-957e-7aeb1b91d8dc,4f047eeb-b78b-4965-be98-13024ebd232c','4wrvkx-my.sharepoint.com,722129ef-a772-4461-972c-5b9ab897f3d6,b7c975e9-cb22-4f66-8652-73e63e470af8'))

createdDateTime

The createdDateTime property supports eq, ne, ge, gt, le, lt, and not query operator. Supported date time format is either YYYY-MM-ddThh:mm:ssZ or YYYY-MM-dd.

GET /v1.0/sites/getAllSites?$filter=createdDateTime eq 2023-02-21T19:58:39Z
GET /v1.0/sites/getAllSites?$filter=createdDateTime ne 2023-02-21T19:58:39Z
GET /v1.0/sites/getAllSites?$filter=createdDateTime ge 2023-02-21T19:58:39Z
GET /v1.0/sites/getAllSites?$filter=createdDateTime gt 2023-02-21T19:58:39Z
GET /v1.0/sites/getAllSites?$filter=createdDateTime le 2023-02-21T19:58:39Z
GET /v1.0/sites/getAllSites?$filter=createdDateTime lt 2023-02-21T19:58:39Z
GET /v1.0/sites/getAllSites?$filter=not(createdDateTime eq 2023-02-21T19:58:39Z)
GET /v1.0/sites/getAllSites?$filter=createdDateTime eq 2023-02-21
GET /v1.0/sites/getAllSites?$filter=createdDateTime ne 2023-02-21
GET /v1.0/sites/getAllSites?$filter=createdDateTime ge 2023-02-21
GET /v1.0/sites/getAllSites?$filter=createdDateTime gt 2023-02-21
GET /v1.0/sites/getAllSites?$filter=createdDateTime le 2023-02-21
GET /v1.0/sites/getAllSites?$filter=createdDateTime lt 2023-02-21
GET /v1.0/sites/getAllSites?$filter=not(createdDateTime eq 2023-02-21)
GET /v1.0/sites/getAllSites?$filter=createdDateTime gt 2023-02-21 and createdDateTime lt 2023-02-25

name

The name property supports eq, ne, contains, startsWith, endsWith, in, and not query operator. Be aware of case sensitivity.

GET /v1.0/sites/getAllSites?$filter=name eq 'Communication site'
GET /v1.0/sites/getAllSites?$filter=name ne 'Communication site'
GET /v1.0/sites/getAllSites?$filter=contains(name,'Communication') - case sensitive
GET /v1.0/sites/getAllSites?$filter=startsWith(name,'Comm') - case sensitive
GET /v1.0/sites/getAllSites?$filter=endsWith(name,'site') - case sensitive
GET /v1.0/sites/getAllSites?$filter=name in ('Sample Team Site','Team Site')
GET /v1.0/sites/getAllSites?$filter=not(name in ('Sample Team Site','Team Site'))

webUrl

The webUrl property supports eq, ne, contains, startsWith, endsWith, in, and not query operator.

GET /v1.0/sites/getAllSites?$filter=webUrl eq 'https://4wrvkx.sharepoint.com/'
GET /v1.0/sites/getAllSites?$filter=webUrl ne 'https://4wrvkx.sharepoint.com/'
GET /v1.0/sites/getAllSites?$filter=contains(webUrl,'https://4wrvkx.sharepoint.com/')
GET /v1.0/sites/getAllSites?$filter=startsWith(webUrl,'https://4wrvkx.sharepoint.com/')
GET /v1.0/sites/getAllSites?$filter=endsWith(webUrl,'sharepoint.com/')
GET /v1.0/sites/getAllSites?$filter=webUrl in ('https://4wrvkx-my.sharepoint.com/personal/gradya_4wrvkx_onmicrosoft_com','https://4wrvkx-my.sharepoint.com/personal/henriettam_4wrvkx_onmicrosoft_com')
GET /v1.0/sites/getAllSites?$filter=not(webUrl in ('https://4wrvkx-my.sharepoint.com/personal/gradya_4wrvkx_onmicrosoft_com','https://4wrvkx-my.sharepoint.com/personal/henriettam_4wrvkx_onmicrosoft_com'))

displayName

The displayName property supports eq, ne, contains, startsWith, endsWith, in, and not query operator.

GET /v1.0/sites/getAllSites?$filter=displayName eq 'Communication site'
GET /v1.0/sites/getAllSites?$filter=displayName ne 'Communication site'
GET /v1.0/sites/getAllSites?$filter=contains(displayName,'Communication') - case sensitive
GET /v1.0/sites/getAllSites?$filter=startsWith(displayName,'Comm') - case sensitive
GET /v1.0/sites/getAllSites?$filter=endsWith(displayName,'site') - case sensitive
GET /v1.0/sites/getAllSites?$filter=displayName in ('Sample Team Site','Team Site')
GET /v1.0/sites/getAllSites?$filter=not(displayName in ('Sample Team Site','Team Site'))

siteCollection/hostname

The siteCollection/hostname property supports eq, ne, contains, startsWith, endsWith, in, and not query operator.

GET /v1.0/sites/getAllSites?$filter=siteCollection/hostname eq '4wrvkx-my.sharepoint.com'
GET /v1.0/sites/getAllSites?$filter=siteCollection/hostname ne '4wrvkx-my.sharepoint.com'
GET /v1.0/sites/getAllSites?$filter=contains(siteCollection/hostname, 'my')
GET /v1.0/sites/getAllSites?$filter=beginsWith(siteCollection/hostname, '4wrvkx')
GET /v1.0/sites/getAllSites?$filter=endsWith(siteCollection/hostname, 'sharepoint.com')
GET /v1.0/sites/getAllSites?$filter=siteCollection/hostname in ('4wrvkx.sharepoint.com','4wrvkx-my.sharepoint.com')
GET /v1.0/sites/getAllSites?$filter=not(siteCollection/hostname in ('4wrvkx.sharepoint.com','4wrvkx-my.sharepoint.com'))

siteCollection/dataLocationCode

The siteCollection/dataLocationCode property supports eq, ne, contains, startsWith, endsWith, in, and not query operator.

GET /v1.0/sites/getAllSites?$filter=siteCollection/dataLocationCode eq 'JPN'
GET /v1.0/sites/getAllSites?$filter=siteCollection/dataLocationCode ne 'JPN'
GET /v1.0/sites/getAllSites?$filter=contains(siteCollection/dataLocationCode, 'O')
GET /v1.0/sites/getAllSites?$filter=beginsWith(siteCollection/dataLocationCode, 'C')
GET /v1.0/sites/getAllSites?$filter=endsWith(siteCollection/dataLocationCode, 'OR')
GET /v1.0/sites/getAllSites?$filter=siteCollection/dataLocationCode in ('EUR','JPN')
GET /v1.0/sites/getAllSites?$filter=not(siteCollection/dataLocationCode in ('EUR','JPN'))

The possible values for dataLocationCode are:

Code Geo location
APC Macro Region Geography 2 - Asia-Pacific
AUS Australia
BRA Brazil
CAN Canada
EUR Macro Region Geography 1 - EMEA
FRA France
DEU Germany
IND India
JPN Japan
KOR Korea
NAM Macro Region Geography 3 - Americas
NOR Norway
QAT Qatar
POL Poland
ZAF South Africa
SWE Sweden
CHE Switzerland
ARE United Arab Emirates
GBR United Kingdom

Orderby

All properties support ordering.

GET /v1.0/sites/getAllSites?$orderby=createdDateTime
GET /v1.0/sites/getAllSites?$orderby=createdDateTime desc
GET /v1.0/sites/getAllSites?$orderby=id
GET /v1.0/sites/getAllSites?$orderby=id desc
GET /v1.0/sites/getAllSites?$orderby=name
GET /v1.0/sites/getAllSites?$orderby=name desc
GET /v1.0/sites/getAllSites?$orderby=webUrl
GET /v1.0/sites/getAllSites?$orderby=webUrl desc
GET /v1.0/sites/getAllSites?$orderby=displayName
GET /v1.0/sites/getAllSites?$orderby=displayName desc
GET /v1.0/sites/getAllSites?$orderby=siteCollection/hostname
GET /v1.0/sites/getAllSites?$orderby=siteCollection/hostname desc
GET /v1.0/sites/getAllSites?$orderby=siteCollection/dataLocationCode
GET /v1.0/sites/getAllSites?$orderby=siteCollection/dataLocationCode desc

Top and SkipToken

The $top query operator is supported together with $skipToken query operator.

GET /v1.0/sites/getAllSites?$top=15
GET /v1.0/sites/getAllSites?$top=15&$skiptoken=UGFnZWQ9VFJVRSZwX0ZpbGVMZWFmUmVmPTI0Xy4wMDAmcF9JRD0yNA

Expand

The $expand query parameter is not supported. The query with $expand doesn't throw an exception, but the $expand is ignored.

Conclusion

I need to appreciate a great work of the Microsoft Graph team. Pros is that the getAllSites endpoint support almost all OData query parameters which is still not a standard in the Graph API.

0
Buy Me a Coffee at ko-fi.com
An error has occurred. This application may no longer respond until reloaded. Reload x