Using the SharePoint Online REST API, I'm trying to retrieve a list of all sites and subsites.
This API gives me all top level sites, but no subsites:
https://{mycompany}.sharepoint.com/_api/search/query
?querytext='contentclass:STS_Site'
Either of these APIs gives me all sub-sites of the root top level site:
https://{mycompany}.sharepoint.com/_api/search/query
?querytext='contentclass:STS_Web'
https://{mycompany}.sharepoint.com/_api/search/query?
querytext='*'
&refinementfilters='contentclass:equals("STS_Web")'
I'd like a single query which retrieves all sites and all of their subsites -- not just subsites of the root site.
Edit:
Now I've had time to come back to this, as suggested by @Gautam Sheth I've tried this:
https://{mycompany}.sharepoint.com/_api/search/query
?querytext='contentclass:STS_Site contentclass:STS_Web'
&selectproperties='Title,Path'&rowlimit=500
It's not quite working though. In a site structured like so, only the checked (✔✅) sites and subsites are being returned in the response:
- ✔✅ Example Inc - Team Site (the default root site)
- ✔✅ Subsite of Example Inc - Team Site
- Nested subsite of Subsite of Example Inc - Team Site
- Nested subsite #2 of Subsite of Example Inc - Team Site
- Subsite #2 of Example Inc - Team Site
- Subsite #3 of Example Inc - Team Site
- ✔✅ Subsite of Example Inc - Team Site
- ✔✅ David's Test Site (another top level site)
- Subsite of David's Test Site