Skip to main content
edited body
Source Link
dvdsmpsn
  • 231
  • 1
  • 3
  • 13

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
  • David's Test Site (another top level site)
    • Subsite of David's Test Site

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
  • David's Test Site (another top level site)
    • Subsite of David's Test Site

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
  • David's Test Site (another top level site)
    • Subsite of David's Test Site
Tweeted twitter.com/StackSharePoint/status/1022497009650098177
With new findings
Source Link
dvdsmpsn
  • 231
  • 1
  • 3
  • 13

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'STS_Site'

This APIEither of these APIs gives me all sub-sites of the root top level site:

https://{mycompany}.sharepoint.com/_api/search/query
   ?querytext='*'&trim&refinementfilters='contentclassquerytext='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
  • ✔ David's Test Site (another top level site)
    • Subsite of David's Test Site

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'

This API gives me all sub-sites of the root top level site:

https://{mycompany}.sharepoint.com/_api/search/query?querytext='*'&trim&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.

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
  • ✔ David's Test Site (another top level site)
    • Subsite of David's Test Site
Updated to latest syntax.
Source Link
dvdsmpsn
  • 231
  • 1
  • 3
  • 13

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=%27contentclassquerytext='contentclass:sts_site%27sts_site'

This API gives me all sub-sites of the root top level site:

https://{mycompany}.sharepoint.com/_api/search/query?querytext=%27*%27&trim&refinementfilters=%27contentclassquerytext='*'&trim&refinementfilters='contentclass:equals(%22STS_Web%22"STS_Web")%27'

I'd like a single query which retrieves all sites and all of their subsites -- not just subsites of the root site.

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=%27contentclass:sts_site%27

This API gives me all sub-sites of the root top level site:

https://{mycompany}.sharepoint.com/_api/search/query?querytext=%27*%27&trim&refinementfilters=%27contentclass:equals(%22STS_Web%22)%27

I'd like a single query which retrieves all sites and all of their subsites -- not just subsites of the root site.

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'

This API gives me all sub-sites of the root top level site:

https://{mycompany}.sharepoint.com/_api/search/query?querytext='*'&trim&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.

added 4 characters in body
Source Link
dvdsmpsn
  • 231
  • 1
  • 3
  • 13
Loading
edited title
Link
dvdsmpsn
  • 231
  • 1
  • 3
  • 13
Loading
Source Link
dvdsmpsn
  • 231
  • 1
  • 3
  • 13
Loading