2

Is there any API to fetch all the trending documents in My Site.

1 Answer 1

0

We can get trending documents from a particular location(like shared documents). Please refer below code,

var queryTrendingUrl = "/_api/search/query?querytext='path:http://siteurl/ShearedDocuments/'&sortlist='ViewsLifeTime:descending'";
getItems(queryTrendingUrl).done(function (data) {
    data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results.forEach(function (item) {
        //Get doc properties like below
        var docTitle = item.Cells.results[3]["Value"];
    });
}); 


//Get Data from sharepoint list or library
function getItems(url) {
    return $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + url,
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        }
    });
}

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.