1

I wonder if It's possible to get all my site collection names or paths in Javascript, Visual Studios. I've found them through REST when I put server/_api/search/query?querytext='sharepoint' in the adressbar in Internet Explorer. I'm using SharePoint Online in Office 365. But how do I do it code wise in Javascript. I've tried some examples but none have worked.

Thanks in advance!

2

1 Answer 1

0

I got it to work so I will share my victory with you. This code works if you need to get the Site collections paths, title etc.

var queryUrl = spAppWebUrl + "/_api/search/query?querytext='sharepoint'&trimduplicates=false&rowlimit=400&refinementfilters='contentclass:equals("STS_Site")'

 $.ajax({ url: queryUrl, method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: onQuerySuccess, error: onQueryError });
    });

function onQuerySuccess(data) {
var results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;

$("#resultsDiv").append('<table>');

$.each(results, function () {
    $("#resultsDiv").append('<tr>');
    $.each(this.Cells.results, function () {



        if (this.Key == "Title") {

            $("#resultsDiv").append('<td>' + this.Value + '</td>');
        }
        if (this.Key == "Path") {
            $("#resultsDiv").append('<td>' + this.Value + '</td>');
        }

    });
    $("#resultsDiv").append('</tr>');
});
$("#resultsDiv").append('</table>');}

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.