通過getfilebyserverrelativeurl
端點
Endpoint Uri: /_api/web/getfilebyserverrelativeurl('<file url>')/ListItemAllFields/breakroleinheritance(true)
Method: POST
Headers {Accept: application/json;odata=verbose, X-RequestDigest: <value>}
其中file url
是服務器相對URL到文件
JavaScript示例:
function breakRoleInheritance(webUrl,fileUrl) {
return $.ajax({
url: webUrl + "/_api/web/GetFileByServerRelativeUrl('" + fileUrl + "')/ListItemAllFields/breakroleinheritance(copyRoleAssignments=true,clearSubscopes=true)",
type: "POST",
contentType: "application/json;odata=verbose",
headers: {
"Accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val()
}
});
}
通過ListItem
資源
Endpoint Uri: /_api/web/lists/getByTitle('<list title>')/items('<id>')/breakroleinheritance(copyRoleAssignments=true,clearSubscopes=true)
Method: POST
Headers {Accept: application/json;odata=verbose, X-RequestDigest: <value>}
其中list title
列表或庫標題,id
- 列表項關聯 與文件