8

I am trying to get all subsites from a parent web using REST API. I tried following query which shows "The page cannot be found".

mysite/_api/web/parentWeb/webs

3 Answers 3

11

Suppose, your site url is like this: http://yourcompany.com/sites/projects

Then in order to get sus site under projects site use:

http://yourcompany.com/sites/projects/_api/web/webs

Suppose you have site under projects named "Project1" and you want to find subsite under it, then use:

http://yourcompany.com/sites/projects/Project1/_api/web/webs
1
  • thanks, unfortunately the url can be changed. I wanted to get all siblings by going up one step and get all subsites.
    – Medes
    Commented Mar 10, 2014 at 8:37
6

The following REST endpoint

/_api/site/rootWeb/webinfos

will return the collection of sub webs (WebInfo objects) under root web

Using Search REST API

The following REST query demonstrates how to find all webs under the specified path:

/_api/search/query?querytext='path:https://contoso.sharepoint.com/*'&refinementfilters='contentclass:equals("STS_Web")'
7
  • thanks, this piece of code is running almost everywhere and I want to get all siblings by going up only one step and get all subsites.
    – Medes
    Commented Mar 10, 2014 at 8:35
  • Medes,in that case you could utilize search based approach in order to return all webs, the answer has been updated. Commented Mar 10, 2014 at 8:52
  • yes, still I need to have a dynamic value of "Path"? am I right?
    – Medes
    Commented Mar 10, 2014 at 9:03
  • it depends, you could specify site collection path (static), or if needed to return results relative to specific parent web, then path should be constructed (dynamic) Commented Mar 10, 2014 at 9:17
  • Vadim, I tested your query but it didn't work,
    – Medes
    Commented Mar 10, 2014 at 10:30
2

For up to date list (contrary to search) that also works for users with read-only permissions (contrary to /_api/web/webs), use this REST api:

http://<sitecollection>/<site>/_api/web/GetSubwebsFilteredForCurrentUser(nWebTemplateFilter=-1,nConfigurationFilter=-1)

Your Answer

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

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