ReinerM
ReinerM

Reputation: 7

Sharepoint Rest API breakRoleInheritance Of Folder

I have create a Doc-set and in the Docset folders. I like to break role inheritance on the folder. I am new in SharePoint Rest-API and I couldn’t find the right endpoint. Can I use /breakroleinheritance(true) for this?

One of my tests:

function breakRoleInheritanceOfFolder() {
    $.ajax({
      url: siteUrl 
         + "/_api/web/getfolderbyserverrelativeurl(‘List1/DocSet2/Folder3’)''
         +”/breakroleinheritance(true)",             
     type: 'POST',
     headers: { 'X-RequestDigest':$('#__REQUESTDIGEST').val() },  
     success: successHandler,
     error: errorHandler
    });
}

But it doesn't work. We use Sharepoint 2016 On-Premises.

Upvotes: 0

Views: 4254

Answers (1)

LZ_MSFT
LZ_MSFT

Reputation: 4208

The following code for your reference.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(function () {
    breakRoleInheritanceOfFolder("List1/DocSet2/Folder3");
});
function breakRoleInheritanceOfFolder(folderRelativeUrl){
    // begin work to call across network
    var requestUri = _spPageContextInfo.webAbsoluteUrl +
                  "/_api/web/GetFolderByServerRelativeUrl('"+folderRelativeUrl+"')/ListItemAllFields/breakroleinheritance(true)";

    // execute AJAX request
    $.ajax({
        url: requestUri,
        type: "POST",
        contentType: "application/json;odata=verbose",
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {                 
            alert("succeeded");
        },
        error: function () {
            alert("Failed to get details");
        }
    });
}
</script>

Upvotes: 3

Related Questions