How to get all the sitecollections of sharepoint online using REST api, I used the following end point.But it doesn't seems to give me all the sitecollections.
https://xxxxxx.sharepoint.com/_api/search/query?querytext='contentclass:sts_site'
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityHow to get all the sitecollections of sharepoint online using REST api, I used the following end point.But it doesn't seems to give me all the sitecollections.
https://xxxxxx.sharepoint.com/_api/search/query?querytext='contentclass:sts_site'
Currently, there is no Rest API endpoint would get the Site Collections list from tenant directly. In Rest API, the only workaround is to use search API with contentclass:sts_site
.
But in SharePoint, when results are returned for a user's search, the Query engine performs an access check for the user's identity against the security descriptor stored in the content index for each item in the search results. The Query engine then removes any items in the search results that the user does not have access to, so that the user never sees these results. It means, user won’t see site collections he doesn’t have permission with in results.
There is no CSOM workaround for that.
Currently, we can only connect to SharePoint Online to get all site collections using PowerShell Get-SPOSite or using PnP-PowerShell Get-PnPTenantSite
A demo:
# Input credential
$adminUPN="<user>@<tenant>.onmicrosoft.com"
$userCredential = Get-Credential -UserName $adminUPN -Message "Type the password."
# Connect to SharePoint Online Admin Center
Connect-SPOService -Url https://<tenant>-admin.sharepoint.com/ -Credential $userCredential
# Get all site collections
$sites = Get-SPOSite -Limit All
# Iterate the site collections
foreach ($site in $sites) {
Write-Host "Title: "$site.Title
Write-Host "Url: "$site.Url
Write-Host "-------------------------"
}
_api/search/query?querytext='contentclass:sts_site'&rowlimit=500
and check