1

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'

  • 2
    It is permission trimmed, so will only see the site collections to which you have access. You can also specify the rowLimit as _api/search/query?querytext='contentclass:sts_site'&rowlimit=500 and check – Gautam Sheth Jan 17 at 14:11
  • But sharepoint online shell seems to be getting all the sitecollections – sai monesh Jan 17 at 16:38
1

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 "-------------------------"
}
  • So it will not be possible using rest api – sai monesh Jan 18 at 7:18
  • Also How to create client context if there -legacyauthprotocol is enabled in csom – sai monesh Jan 18 at 7:23
  • refer to: morgantechspace.com/2016/02/… – JoannaW_MSFT Jan 18 at 8:30
  • How to create client context if there -legacyauthprotocol is disabled in csom.without changing it back – sai monesh Jan 18 at 9:42

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.