命名空间:microsoft.graph
重要
Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
将敏感度标签异步分配给 driveItem。
此 API 是执行高级高级管理功能的 Microsoft SharePoint 和 OneDrive API 的一部分,被视为受保护的。 受保护的 API 需要进行更多验证(权限和同意之外)才能使用。
从管理员的角度来看,有关敏感度标签的详细信息,请参阅 为 SharePoint 和 OneDrive 中的 Office 文件启用敏感度标签。
此 API 将敏感度标签应用于静态文件。 Office 客户端不会对包含标签信息的文件应用水印、页眉或页脚。 从管理员的角度来看,有关敏感度标签的详细信息,请参阅 为 SharePoint 和 OneDrive 中的 Office 文件启用敏感度标签。
API 可用性
此 API 可用于以下国家级云部署。
| 全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
| ✅ |
❌ |
❌ |
❌ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
| 权限类型 |
最低特权权限 |
更高特权权限 |
| 委派(工作或学校帐户) |
Files.ReadWrite.All |
Sites.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
| 应用程序 |
Files.ReadWrite.All |
Sites.ReadWrite.All |
注意
对于 Microsoft SharePoint Embedded 容器,仅限应用程序的请求需要此 appliedByUser 参数。
HTTP 请求
POST /drives/{drive-id}/items/{item-id}/assignSensitivityLabel
POST /drives/{drive-id}/root:/{item-path}:/assignSensitivityLabel
POST /groups/{group-id}/drive/items/{item-id}/assignSensitivityLabel
POST /groups/{group-id}/drive/root:/{item-path}:/assignSensitivityLabel
POST /me/drive/items/{item-id}/assignSensitivityLabel
POST /me/drive/root:/{item-path}:/assignSensitivityLabel
POST /sites/{site-id}/drive/items/{item-id}/assignSensitivityLabel
POST /sites/{site-id}/drive/root:/{item-path}:/assignSensitivityLabel
POST /users/{user-id}/drive/items/{item-id}/assignSensitivityLabel
POST /users/{user-id}/drive/root:/{item-path}:/assignSensitivityLabel
| 名称 |
说明 |
| Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
请求正文
在请求正文中,提供要分配给给定文件的敏感度标签的 ID。 下表列出了必需和可选的输入参数。
| 名称 |
值 |
说明 |
| sensitivityLabelId |
String |
必填。 要分配的敏感度标签的 ID,或用于删除敏感度标签的空字符串。 |
| assignmentMethod |
sensitivityLabelAssignmentMethod |
可选。 文档上标签的分配方法。 指示标签分配是自动完成的、标准的还是作为特权操作完成的, (等效于管理员操作) 。 |
| justificationText |
String |
可选。 用于审核目的的对齐文本。 降级或删除标签时需要。 |
| appliedByUser |
userIdentity |
可选。 代表其应用标签的用户的标识。 仅在应用程序 (仅应用) 环境中受支持。 指定 id (Microsoft Entra 对象 ID) 或 userPrincipalName. |
响应
如果成功,API 将返回 202 Accepted 带有空响应正文的 HTTP 响应代码。
Location标头提供用于获取操作详细信息的 URL。
有关如何监视分配敏感度标签操作进度的详细信息,请参阅 监视长时间运行的操作。
除了适用于 Microsoft Graph 的一般错误外,此 API 还会返回响应 423 Locked 代码,该代码指示正在访问的文件已锁定。 在这种情况下,响应对象的 code 属性指示阻止操作的错误类型。
此外,某些受 IRM 保护的敏感度标签无法在仅应用模式下更新,需要委派的用户访问权限来验证用户是否具有适当的权限。 对于这些方案,API 会引发 Not Supported 响应代码。
下表列出了错误类型的可能值。
| 值 |
说明 |
| fileDoubleKeyEncrypted |
指示文件受双密钥加密保护;因此,无法将其打开。 |
| fileDecryptionNotSupported |
指示加密文件具有特定属性,不允许 SharePoint 打开这些文件。 |
| fileDecryptionDeferred |
指示正在处理文件以进行解密;因此,无法将其打开。 |
| unknownFutureValue |
可进化枚举哨兵值。 请勿使用。 |
示例
示例 1:分配敏感度标签
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/beta/drive/root/items/016GVDAP3RCQS5VBQHORFIVU2ZMOSBL25U/assignSensitivityLabel
Content-Type: application/json
{
"sensitivityLabelId": "5feba255-812e-446a-ac59-a7044ef827b5",
"assignmentMethod": "standard",
"justificationText": "test_justification"
}
const options = {
authProvider,
};
const client = Client.init(options);
const assignSensitivityLabel = {
sensitivityLabelId: '5feba255-812e-446a-ac59-a7044ef827b5',
assignmentMethod: 'standard',
justificationText: 'test_justification'
};
await client.api('/drive/root/items/016GVDAP3RCQS5VBQHORFIVU2ZMOSBL25U/assignSensitivityLabel')
.version('beta')
.post(assignSensitivityLabel);
响应
以下示例显示了相应的响应。
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/QXNzaWduU2Vuc2l0aXZpdHlMYWJlbCxiMzc3ODY3OS04OWQ3LTRkYmYtYjg0MC1jYWM1NzRhY2FlNmE?tempAuth=eyJ0eXAiOiJKV1QiLCJhb....
标头的值 Location 为服务提供 URL,该服务将返回 assignSensitivityLabel 操作的当前状态。
可以使用此信息来 确定 assignSensitivityLabel 操作何时完成。
示例 2:代表用户分配仅限应用 () 的敏感度标签
请求
以下示例演示了仅限应用的请求,该请求代表特定用户分配标签,该标签由 Microsoft Entra 对象 ID 标识。
POST https://graph.microsoft.com/beta/drives/{drive-id}/items/016GVDAP3RCQS5VBQHORFIVU2ZMOSBL25U/assignSensitivityLabel
Content-Type: application/json
{
"sensitivityLabelId": "5feba255-812e-446a-ac59-a7044ef827b5",
"assignmentMethod": "standard",
"justificationText": "test_justification",
"appliedByUser": {
"id": "4a2ec3c4-1b2d-3e4f-5a6b-7c8d9e0f1a2b"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.AssignSensitivityLabel;
using Microsoft.Graph.Beta.Models;
var requestBody = new AssignSensitivityLabelPostRequestBody
{
SensitivityLabelId = "5feba255-812e-446a-ac59-a7044ef827b5",
AssignmentMethod = SensitivityLabelAssignmentMethod.Standard,
JustificationText = "test_justification",
AppliedByUser = new UserIdentity
{
Id = "4a2ec3c4-1b2d-3e4f-5a6b-7c8d9e0f1a2b",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].AssignSensitivityLabel.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphdrives.NewAssignSensitivityLabelPostRequestBody()
sensitivityLabelId := "5feba255-812e-446a-ac59-a7044ef827b5"
requestBody.SetSensitivityLabelId(&sensitivityLabelId)
assignmentMethod := graphmodels.STANDARD_SENSITIVITYLABELASSIGNMENTMETHOD
requestBody.SetAssignmentMethod(&assignmentMethod)
justificationText := "test_justification"
requestBody.SetJustificationText(&justificationText)
appliedByUser := graphmodels.NewUserIdentity()
id := "4a2ec3c4-1b2d-3e4f-5a6b-7c8d9e0f1a2b"
appliedByUser.SetId(&id)
requestBody.SetAppliedByUser(appliedByUser)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").AssignSensitivityLabel().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.assignsensitivitylabel.AssignSensitivityLabelPostRequestBody assignSensitivityLabelPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.assignsensitivitylabel.AssignSensitivityLabelPostRequestBody();
assignSensitivityLabelPostRequestBody.setSensitivityLabelId("5feba255-812e-446a-ac59-a7044ef827b5");
assignSensitivityLabelPostRequestBody.setAssignmentMethod(SensitivityLabelAssignmentMethod.Standard);
assignSensitivityLabelPostRequestBody.setJustificationText("test_justification");
UserIdentity appliedByUser = new UserIdentity();
appliedByUser.setId("4a2ec3c4-1b2d-3e4f-5a6b-7c8d9e0f1a2b");
assignSensitivityLabelPostRequestBody.setAppliedByUser(appliedByUser);
graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").assignSensitivityLabel().post(assignSensitivityLabelPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const assignSensitivityLabel = {
sensitivityLabelId: '5feba255-812e-446a-ac59-a7044ef827b5',
assignmentMethod: 'standard',
justificationText: 'test_justification',
appliedByUser: {
id: '4a2ec3c4-1b2d-3e4f-5a6b-7c8d9e0f1a2b'
}
};
await client.api('/drives/{drive-id}/items/016GVDAP3RCQS5VBQHORFIVU2ZMOSBL25U/assignSensitivityLabel')
.version('beta')
.post(assignSensitivityLabel);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\AssignSensitivityLabel\AssignSensitivityLabelPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\SensitivityLabelAssignmentMethod;
use Microsoft\Graph\Beta\Generated\Models\UserIdentity;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AssignSensitivityLabelPostRequestBody();
$requestBody->setSensitivityLabelId('5feba255-812e-446a-ac59-a7044ef827b5');
$requestBody->setAssignmentMethod(new SensitivityLabelAssignmentMethod('standard'));
$requestBody->setJustificationText('test_justification');
$appliedByUser = new UserIdentity();
$appliedByUser->setId('4a2ec3c4-1b2d-3e4f-5a6b-7c8d9e0f1a2b');
$requestBody->setAppliedByUser($appliedByUser);
$graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->assignSensitivityLabel()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
sensitivityLabelId = "5feba255-812e-446a-ac59-a7044ef827b5"
assignmentMethod = "standard"
justificationText = "test_justification"
appliedByUser = @{
id = "4a2ec3c4-1b2d-3e4f-5a6b-7c8d9e0f1a2b"
}
}
Set-MgBetaDriveItemSensitivityLabel -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.drives.item.items.item.assign_sensitivity_label.assign_sensitivity_label_post_request_body import AssignSensitivityLabelPostRequestBody
from msgraph_beta.generated.models.sensitivity_label_assignment_method import SensitivityLabelAssignmentMethod
from msgraph_beta.generated.models.user_identity import UserIdentity
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AssignSensitivityLabelPostRequestBody(
sensitivity_label_id = "5feba255-812e-446a-ac59-a7044ef827b5",
assignment_method = SensitivityLabelAssignmentMethod.Standard,
justification_text = "test_justification",
applied_by_user = UserIdentity(
id = "4a2ec3c4-1b2d-3e4f-5a6b-7c8d9e0f1a2b",
),
)
await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').assign_sensitivity_label.post(request_body)
响应
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/QXNzaWduU2Vuc2l0aXZpdHlMYWJlbCxiMzc3ODY3OS04OWQ3LTRkYmYtYjg0MC1jYWM1NzRhY2FlNmE?tempAuth=******
示例 3:使用仅) 限应用的用户主体名称代表用户 (分配敏感度标签
请求
以下示例显示了一个仅限应用的请求,该请求通过用户主体名称标识用户。
POST https://graph.microsoft.com/beta/drives/{drive-id}/items/016GVDAP3RCQS5VBQHORFIVU2ZMOSBL25U/assignSensitivityLabel
Content-Type: application/json
{
"sensitivityLabelId": "5feba255-812e-446a-ac59-a7044ef827b5",
"assignmentMethod": "standard",
"justificationText": "test_justification",
"appliedByUser": {
"userPrincipalName": "adelev@contoso.com"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Drives.Item.Items.Item.AssignSensitivityLabel;
using Microsoft.Graph.Beta.Models;
var requestBody = new AssignSensitivityLabelPostRequestBody
{
SensitivityLabelId = "5feba255-812e-446a-ac59-a7044ef827b5",
AssignmentMethod = SensitivityLabelAssignmentMethod.Standard,
JustificationText = "test_justification",
AppliedByUser = new UserIdentity
{
UserPrincipalName = "adelev@contoso.com",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].AssignSensitivityLabel.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphdrives "github.com/microsoftgraph/msgraph-beta-sdk-go/drives"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphdrives.NewAssignSensitivityLabelPostRequestBody()
sensitivityLabelId := "5feba255-812e-446a-ac59-a7044ef827b5"
requestBody.SetSensitivityLabelId(&sensitivityLabelId)
assignmentMethod := graphmodels.STANDARD_SENSITIVITYLABELASSIGNMENTMETHOD
requestBody.SetAssignmentMethod(&assignmentMethod)
justificationText := "test_justification"
requestBody.SetJustificationText(&justificationText)
appliedByUser := graphmodels.NewUserIdentity()
userPrincipalName := "adelev@contoso.com"
appliedByUser.SetUserPrincipalName(&userPrincipalName)
requestBody.SetAppliedByUser(appliedByUser)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").AssignSensitivityLabel().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
com.microsoft.graph.beta.drives.item.items.item.assignsensitivitylabel.AssignSensitivityLabelPostRequestBody assignSensitivityLabelPostRequestBody = new com.microsoft.graph.beta.drives.item.items.item.assignsensitivitylabel.AssignSensitivityLabelPostRequestBody();
assignSensitivityLabelPostRequestBody.setSensitivityLabelId("5feba255-812e-446a-ac59-a7044ef827b5");
assignSensitivityLabelPostRequestBody.setAssignmentMethod(SensitivityLabelAssignmentMethod.Standard);
assignSensitivityLabelPostRequestBody.setJustificationText("test_justification");
UserIdentity appliedByUser = new UserIdentity();
appliedByUser.setUserPrincipalName("adelev@contoso.com");
assignSensitivityLabelPostRequestBody.setAppliedByUser(appliedByUser);
graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").assignSensitivityLabel().post(assignSensitivityLabelPostRequestBody);
const options = {
authProvider,
};
const client = Client.init(options);
const assignSensitivityLabel = {
sensitivityLabelId: '5feba255-812e-446a-ac59-a7044ef827b5',
assignmentMethod: 'standard',
justificationText: 'test_justification',
appliedByUser: {
userPrincipalName: 'adelev@contoso.com'
}
};
await client.api('/drives/{drive-id}/items/016GVDAP3RCQS5VBQHORFIVU2ZMOSBL25U/assignSensitivityLabel')
.version('beta')
.post(assignSensitivityLabel);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Drives\Item\Items\Item\AssignSensitivityLabel\AssignSensitivityLabelPostRequestBody;
use Microsoft\Graph\Beta\Generated\Models\SensitivityLabelAssignmentMethod;
use Microsoft\Graph\Beta\Generated\Models\UserIdentity;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AssignSensitivityLabelPostRequestBody();
$requestBody->setSensitivityLabelId('5feba255-812e-446a-ac59-a7044ef827b5');
$requestBody->setAssignmentMethod(new SensitivityLabelAssignmentMethod('standard'));
$requestBody->setJustificationText('test_justification');
$appliedByUser = new UserIdentity();
$appliedByUser->setUserPrincipalName('adelev@contoso.com');
$requestBody->setAppliedByUser($appliedByUser);
$graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->assignSensitivityLabel()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Files
$params = @{
sensitivityLabelId = "5feba255-812e-446a-ac59-a7044ef827b5"
assignmentMethod = "standard"
justificationText = "test_justification"
appliedByUser = @{
userPrincipalName = "adelev@contoso.com"
}
}
Set-MgBetaDriveItemSensitivityLabel -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.drives.item.items.item.assign_sensitivity_label.assign_sensitivity_label_post_request_body import AssignSensitivityLabelPostRequestBody
from msgraph_beta.generated.models.sensitivity_label_assignment_method import SensitivityLabelAssignmentMethod
from msgraph_beta.generated.models.user_identity import UserIdentity
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AssignSensitivityLabelPostRequestBody(
sensitivity_label_id = "5feba255-812e-446a-ac59-a7044ef827b5",
assignment_method = SensitivityLabelAssignmentMethod.Standard,
justification_text = "test_justification",
applied_by_user = UserIdentity(
user_principal_name = "adelev@contoso.com",
),
)
await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').assign_sensitivity_label.post(request_body)
响应
HTTP/1.1 202 Accepted
Location: https://contoso.sharepoint.com/_api/v2.0/monitor/QXNzaWduU2Vuc2l0aXZpdHlMYWJlbCxiMzc3ODY3OS04OWQ3LTRkYmYtYjg0MC1jYWM1NzRhY2FlNmE?tempAuth=******
API 的响应仅指示已接受或拒绝 assignSensitivityLabel 操作。 例如,如果文件类型不受支持或文件是双重加密,则可能会拒绝该操作。 将记录成功和失败案例的审核事件。 有关详细信息,请参阅 审核日志活动。