8

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
3
  • 1
    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: mytenant.sharepoint.com/_api/search/… contentclass:STS_Web'&selectproperties='Title,Path'&rowlimit=500 ............... STS_Web are subsites and STS_Site are the root sites Commented Oct 4, 2019 at 16:16
  • note that if a site is not indexed they won't show up in the results with the contentclass annotation. Commented Oct 10, 2019 at 19:31
  • I've struggled with msGraph with the same OP's problem. There is no adequate documentation for this particular area of msGraph use. Commented Oct 12, 2023 at 13:23

3 Answers 3

18

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Also learning that the graph api omits personal sites where as the sharepoint api does not?
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.
There is also a List Sites API: learn.microsoft.com/en-us/graph/api/…
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=*"
0

I've noticed that this syntax works with the beta version

https://graph.microsoft.com/v1.0/sites?search=All work with beta api

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

GET https://graph.microsoft.com/v1.0/sites?$search=*&$select=id...... bugged out.
When using
GET https://graph.microsoft.com/v1.0/sites?$search=All&$select=id.... it worked.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.