I created a library with images, there are many folders and into folder there are one or many images. I need get the likes(rating) of the image by current user.

Please help me to find the likedby in SharePoint 2016 rest api (Document Library).

                .done(function (response) {

                    $scope.galleryimages = [];

                    var resultfolder = response.data.d.results;

                    angular.forEach(resultfolder, function (valuefolder, key) {
                        galleryService.getImagesByFolder(valuefolder.Title).done(function (response) {

                            angular.forEach(response.data.d.results, function (valueimage, key) {                                   

                                 ¿¿¿ LikedBy ????

                                var image = {
                                    Id: valueimage.ListItemAllFields.ID,
                                    Title: valuecarpeta.Title,
                                    FileRef: valuecarpeta.FileRef



////Query rest api

method: getImagesByFolder

var query = "/_api/web/GetFolderByServerRelativeUrl('galleryimages/" + folderName + "')/files?" + "$select=Name,ServerRelativeUrl&$top=1&$orderby=Name%20asc";

2 Answers 2


You could consider the following options

Option 1.

1) modify the query to include additional information. Since Ratings properties belong to ListItem resource, append the following expression: $expand=ListItemAllFields to the endpoint url

2) once the data is returned perform the filtering by on the client side by Ratings field


var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getfolderbyserverrelativeurl('/sites/contoso/documents')/files?$expand=ListItemAllFields";

     var result =  data.value.filter(function(item){
         if(item.ListItemAllFields.LikedByStringId.indexOf(_spPageContextInfo.userId.toString()) >= 0)
            return item;


Option 2.

Replace the endpoint /_api/web/GetFolderByServerRelativeUrl('<url>')/files with GetItems method:

Method: POST
Data:  {
  "query": {
    "__metadata": {
      "type": "SP.CamlQuery"
    "ViewXml": "<View><Query><Where><Eq><FieldRef Name=\"LikedBy\" LookupId=\"TRUE\"/><Value Type=\"UserMulti\">17</Value></Eq></Where></Query></View>",
    "FolderServerRelativeUrl": "/sites/contoso/Documents/Archive"

     X-RequestDigest: <request digest>
     Accept: "application/json; odata=verbose"
     Content-Type : "application/json; odata=verbose"


  • filtering by Ratings field is perform on the server side

  • file along with associated list items could be retrieved via a single request


var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/Lists/GetByTitle('Documents')/GetItems?$expand=File";
var query = "<View>" +
              "<Query>" +
                  "<Where>" +
                      "<Eq>" +
                         "<FieldRef Name=\"LikedBy\" LookupId=\"TRUE\"/>" +
                         "<Value Type=\"UserMulti\">" +
                              _spPageContextInfo.userId +
                         "</Value>" +
                       "</Eq>" +
                   "</Where>" +
               "</Query>" +

var folderUrl = _spPageContextInfo.webServerRelativeUrl + "/Documents/Archive";

var queryPayload = { "query" :
               "__metadata": { "type": "SP.CamlQuery" },
               "ViewXml": query,
               "FolderServerRelativeUrl": folderUrl 

    var items = data.d.results;
       //console.log(item.LikesCount); //Likes count
       //console.log(item.LikedByStringId); //user ids
       console.log(item.File.Name); //File properties like Name    



function executePost(url,payload){
    return $.ajax({
        url: url,
        method: "POST",
        data: JSON.stringify(queryPayload),
        headers: {
            "X-RequestDigest": $("#__REQUESTDIGEST").val(),
            "Accept": "application/json; odata=verbose",
            "Content-Type": "application/json; odata=verbose"
  • 1
    thank you so much, for this solution. I used the solution Option 2. It worked for me Commented Oct 11, 2017 at 13:03
  • I'm trying option 2 and I am able to filter on the LikedBy and I get the LikesCount, but neither the LikedBy nor the LikedByStringId are included in my results. Any ideas?
    – Rothrock
    Commented Nov 21, 2017 at 0:14
  • So I tried option 1 and again I get the ListItemAllFields, but don't get LikeBy or LikedByStringId.
    – Rothrock
    Commented Nov 21, 2017 at 0:30

Please use the following line of code to get the item information(include LikedBy).

var query = "/_api/web/lists/GetByTitle('galleryimages')/Items?$filter=substringof('/"+folderName+"/',FileRef)&$select=ID,FileLeafRef,Title,FileRef,LikesCount,LikedBy/Title&$top=1&$orderby=FileLeafRef asc&$expand=LikedBy";
  • thank you for you answer me, but the query doesn't return anything. :( filter=substringof('/"+folderName+"/',FileRef) not working, if I remove this one (filter) return records fine. Commented Sep 27, 2017 at 14:22
  • Check whether the value of folderName variable is right or not.
    – LZ_MSFT
    Commented Sep 28, 2017 at 1:16
  • the value is correct, I changed way to consume data, I maked by CSOM. Thank you Commented Sep 28, 2017 at 15:38
  • Yes, we can use JSOM to achieve it.
    – LZ_MSFT
    Commented Sep 29, 2017 at 1:25

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.