Articles about European Sharepoint Hosting Service
SharePoint Hosting – Remove Unique Permissions From SharePoint List And Library Using REST API
In this article, we will see how to remove the unique permissions from the SharePoint list or library items.
In my Documents library, I have a lot of files with unique permissions. I want to remove these unique permissions with the help of REST API. You can see that, I have added 3 files with unique permissions in the Documents library.
Script to remove unique permissions using REST API
We will call the function in the loop. Here variables names i represent the item ID. As we want to remove all the unique permissions from the library, we can start the ID from 1. In the below script, we are calling the myFunction in the loop.
We are also checking for the error code 400 in the error block, which represents that the item was deleted.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
var i = 1; function myFunction() { $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Documents')/items(" + i + ")/ResetRoleInheritance()", type: 'POST', headers: { "Accept": "application/json;odata=verbose", "Content-Type": "application/json;odata=verbose", "X-RequestDigest": $("#__REQUESTDIGEST").val(), "X-HTTP-Method": "POST" }, success: function(data) { console.log('item permissions removed successfully: ID = ' + i); i++; myFunction(); }, error: function(error) { console.log('failed: ID = ' + i); if (error.status = 400) { i++; myFunction(); } else { alert(JSON.stringify(error)); } } }); } myFunction(); |
This will remove the unique permissions from all the files from the document library.
Print article | This entry was posted by Peter on March 28, 2022 at 3:49 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |