Search code examples
javascriptsharepointspservices

Is there a way retrieve data from SharePoint list using JS & keep the list permission private for anonymous users?


I am retrieving data from a SharePoint list using JavaScript as below.

$().SPServices({
   operation: 'GetListItems',
   async: false,
   listName: listName,
   CAMLViewFields: '<ViewFields></ViewFields>',    
   completefunc: function (xData, status) {
     if (status === 'success') {
       // I work with the data in "$(xData.responseXML).find('z\\:row, row')"

     } else {
    console.log('\n Status is ' + status + '\n And data is ' + xData);
    }
  }
});

However, I need to give the list read access to anonymous users for the above solution to work. Is there a way to use JavaScript to retrieve data from SharePoint list and also keep the SharePoint list permission private for anonymous users?


Solution

  • No you can't. Client-side script uses current user permission to access the list so it's impossible to query a private list. But you could:

    1. create a new list (with columns you need) and use MS Flow/Workflow to sync between 2 lists, then query on that list. Of course, the new list needs to be public.

    2. develop a web api. In this web api, you can use another account (or client id/client secret) to query data from the sharepoint list. From client-side script, you query data from this api.