2

I'm looking for a way to get all the site collections for a particular tenant through API.

The URL that lists all site collections is

https://<tenantName>-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx

How can I get this info using a REST API endpoint?

Update 1:

This API call

https://{tenantName}-admin.sharepoint.com/_api/search/query?querytext='contentclass:sts_site'

Doesn't work for me.

I get the following error (500 Internal Server Error)

{
"error": {
    "code": "-1, Microsoft.Office.Server.Search.REST.SearchServiceException",
    "message": {
        "lang": "en-US",
        "value": "An unknown error occurred."
    }
}

}

FYI: I am using Client Credentials Flow to get the access token. App level permissions list doesn't have any permission to Search like in Delegated permissions. Could that be the issue?

2

It is available in Powershell too, if you have downloaded the SharePoint Online module. Not sure what or how you want to use the data, but it is available that way.

http://www.microsoft.com/en-us/download/details.aspx?id=35588

Get-SPOSite -Limit All

You can also use a search query to look at all STS_Site content classes.

  • The search query doesn't work for me. I get >>> { "error": { "code": "-1, Microsoft.Office.Server.Search.REST.SearchServiceException", "message": { "lang": "en-US", "value": "An unknown error occurred." } } } >>>> URL I hit >>> https://{tenantName}-admin.sharepoint.com/_api/search/query?querytext='contentclass:sts_site' >>> The only thing I can think of is that I use client credentials flow to get access token. Is that the issue? – Syed Mauze Rehan Jul 24 '15 at 5:18
  • Updated my question. – Syed Mauze Rehan Jul 24 '15 at 11:12
  • STS_Site option doesn't return the entire list. I am the owner of some and I don't get them in response (I got this search call working using Authorization code grant flow) – Syed Mauze Rehan Aug 1 '15 at 10:53
  • STS_Site returns top level collections that the current user has access to, you'd need to do some sort of impersonated call if you wanted to retrieve everything. – Eric Alexander Aug 3 '15 at 0:45
  • Correct on the STS_Site part, but the problem is that not all Top level sites are returned in that call. I have a list of Top level sites >>> https://<tenantName>-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx >>> But the call returns only 2-3 of these (top level sites) even though the user I am doing the call with has access to ALL of them (he's the site admin/owner for all) If I know the top level sites, getting inner/subsites is easy. – Syed Mauze Rehan Aug 3 '15 at 4:32
1

I found the following link and an older StackExchange question pointing out that you can do it using CSOM but you can't do it with REST API.

  • That doesn't work for me. I am using Client Credentials Flow to get access token. Is that the issue? URL I hit >>> https://{tenantName}-admin.sharepoint.com/_api/search/query?querytext='.... – Syed Mauze Rehan Jul 24 '15 at 5:16
  • Updated my question. – Syed Mauze Rehan Jul 24 '15 at 11:12

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