7

I am looking for a Graph API call which can return to me all of the sites in Sharepoint Online.

Looking at Enumerating Sites: https://learn.microsoft.com/en-us/graph/api/site-list?view=graph-rest-beta&tabs=http

GET https://graph.microsoft.com/beta/sites?filter=siteCollection/root ne null

it doesn't seem to return group-based sites or sub sites.

Looking at Site Search: https://learn.microsoft.com/en-us/graph/api/site-search?view=graph-rest-beta&tabs=http

GET https://graph.microsoft.com/beta/sites?search={query}

this might be more promising but there is no explanation for how "query" should be structured or what it searches against.

My thought was that since all of the site ids begin with the tenant domain that I might be able to search on that and then retrieve every site and subsite for the tenant. But I'm not sure how to perform that query.

Ideally something like:

GET https://graph.microsoft.com/beta/sites?search=id like contoso.microsoft.com
fei0x
  • 4,259
  • 4
  • 17
  • 37
  • It's worth noting that I've abandoned trying to use the Graph API and am now using the Sharepoint API. where I can use this ............... GET: https://mytenant.sharepoint.com/_api/search/query?querytext='contentclass:STS_Site contentclass:STS_Web'&selectproperties='Title,Path'&rowlimit=500 ............... STS_Web are subsites and STS_Site are the root sites – fei0x Oct 04 '19 at 16:16
  • note that if a site is not indexed they won't show up in the results with the contentclass annotation. – fei0x Oct 10 '19 at 19:31

1 Answers1

17

I found this post asking a very similar question.

https://sharepoint.stackexchange.com/questions/230187/retrieve-all-sites-and-all-subsites-from-the-sharepoint-rest-api

And there is a response by 'dvdsmpsn' where he shares that you can retrieve all sites with this call:

https://graph.microsoft.com/v1.0/sites?search=*

Interestingly this doesn't work in the beta version of the graph API (at this time).

This achieves what I wanted so I'm posting this as an answer, but it doesn't quite answer the question of how a search should be formatted so I'll leave this question open for somebody else to answer if they can.

fei0x
  • 4,259
  • 4
  • 17
  • 37
  • Also learning that the graph api omits personal sites where as the sharepoint api does not? – fei0x Sep 24 '19 at 16:51
  • I've been looking into this the last couple days and your answer is exactly what I found. It also appears you can even leave out the asterisk and get the same results. I was REALLY hoping I could get only site COLLECTIONS, but can't seem to find a way to filter. – DaleyKD May 08 '20 at 14:05
  • 1
    There is also a List Sites API: https://learn.microsoft.com/en-us/graph/api/site-list?view=graph-rest-1.0 – Govind Mohan Nov 11 '22 at 20:38
  • I tried using PowerShell but errored ou with * but it errored out ""Syntax error: character '*' is not valid at position 0 in '*'." Invoke-graphrequest -Method GET -Uri "/v1.0/sites?search=*" – Joy George Kunjikkuru May 26 '23 at 18:01