12

I'm currently working on an iOS app which uses _api-services to retrieve data stored in documents libraries of a SharePoint Online. Consuming _api/web/Lists/ works well so far. At the moment the REST service URL is fixed for each site i want to access.

What I need is a way to retrieve all available sites genericly, so that the users only have to enter their toplevel site and credentials and all available sites will be listed. So I need a service call which delievers me the [site]-information for triggering further calls on the related subsites.

http://toplevelsite.sharepoint.com/[site]/_api/web/Lists/...

Does the REST _api offer a possibility to get all sites and subsites or even the whole site structure?

Thanks for any advice solving my problem

13

How to retrieve sub webs under root web

The following REST endpoint

https://contoso.sharepoint.com/_api/site/rootWeb/webinfos

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


How to retrieve sub webs under relative web

Assume the following site structure:

-- Root
    |
    -- Community
       |
       -- Feedback 

Then the following REST endpoint:

https://contoso.sharepoint.com/community/_api/web/webinfos

will return the Feedback sub web under Community web

  • 1
    thanks for the quick answer. this is working relative to a specific site but when i trigger this service relative to the toplevel site i get an empty response { "d": { "results": [] } } – franqus Mar 7 '14 at 11:18
  • @franqus, the answer has been updated – Vadim Gremyachev Mar 7 '14 at 11:50
  • 5
    Calling the /_api/web/webinfos-endpoint on some subsites it returns me { "error": { "code": "-2147024891, System.UnauthorizedAccessException", "message": { "lang": "en-US", "value": "Access denied. You do not have permission to perform this action or access this resource." } } } even if i can visit the sites in the browser with the same account and not getting permission problems. any idea? – franqus Mar 10 '14 at 8:26
1

If the users have sufficient permissions you can use webinfos. But sometimes users do not have access to some of the subsites. Then SharePoint pops up the login prompt and the call does not work (401 error). In this case you have to use /_api/web/Webs and set effectivebasepermissions in the query string.

I have written a relevant post here http://gbasagiannis.me/2016/01/27/find-first-level-subsites-sharepoint-2013-with-rest-api/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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