SharePoint 2013 Apps: Get list of site collections using REST API

Let me clear that it is not possible to fetch a list of site collection neither via REST nor by using JSOM. But there is a workaround i.e. by utilizing SharePoint Search Query REST/JSOM API. For that a basic search site collection should already be configured and crawled. Then in our code, we only need to specify the query contentclass:sts_site to return sites results. Following is the working code snippet that I used to achieve that:

     
function GetAllSiteCollectionsInCurrentWebApp(currentUser) {

var queryText = 'contentclass:sts_site';
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext='" + queryText + "'";
var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl);
executor.executeAsync({
url: url,
method: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function (data) {
//RetrieveSiteCollectioninWebApp(data, currentUser)
},
error: function (data) {

}
});
}

Sources:

  • http://www.sharepointnutsandbolts.com/2013/01/calling-sharepoint-search-using-rest-eg.html
  • http://stackoverflow.com/questions/25569281/what-is-the-rest-endpoint-url-to-get-the-list-of-site-collections-in-sharepoint?rq=1

Vaqar Hyder

E: vaqar.hyder3567@gmail.com

A:

Siebenb�rgen Stra�e 2/1, Korntal-M�nchingen, 70825, PK

Hire me on Freelancer.com

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *