Hi @大坂 翔 ,
First we need to break role inheritance for the folder.
function breakRoleInheritanceOfFile() {
$.ajax({
url: siteurl + String.format("/_api/web/GetFolderByServerRelativeUrl('DocumentTest/test999')/ListItemAllFields/breakroleinheritance(true)"),
type: "POST",
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
},
success: onQuerySucceeded,
error: onQueryFailed
});
}
Remove the current role assignment for the folder
function remove(){
$.ajax({
url: siteurl + String.format("/_api/web/GetFolderByServerRelativeUrl('DocumentTest/test999')/ListItemAllFields/roleassignments/getbyprincipalid(11)"),
method: "POST",
headers: {
Authorization: "Bearer " + accessToken,
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-HTTP-Method": "DELETE"
},
success: onQuerySucceeded,
error: onQueryFailed
});
}
Add the new role assignment for the folder
function add(){
$.ajax({
url: siteurl + String.format("/_api/web/GetFolderByServerRelativeUrl('DocumentTest/test999')/ListItemAllFields/roleassignments/addroleassignment(principalid=11,roledefid=1073741829)"),
method: "POST",
headers: {
Authorization: "Bearer " + accessToken,
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose"
},
success: onQuerySucceeded,
error: onQueryFailed
});
}
In order to use this API we need 'FullControl' permissions,So we need get Access Token by app
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.