driveItem: lockOrUnlockRecord
이 문서의 내용
Namespace: microsoft.graph
Lock or unlock a retention label on a driveItem that classifies content as records.
For information about retention labels from an administrator's perspective, see Use retention labels to manage the lifecycle of documents stored in SharePoint .
For more information about how you can lock and unlock retention labels, see Use record versioning to update records stored in SharePoint or OneDrive .
This API is available in the following national cloud deployments .
Global service
US Government L4
US Government L5 (DOD)
China operated by 21Vianet
✅
✅
✅
✅
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Type
Permissions (from least to most privileged)
Delegated (work or school account)
Files.ReadWrite.All, Sites.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
Files.ReadWrite.All, Sites.ReadWrite.All
HTTP request
PATCH /driveitem/retentionLabel
PATCH /drives/{drive-id}/items/{item-id}/retentionLabel
Request body
In the request body, provide a JSON object with the following parameter.
Property
Type
Description
retentionSettings
retentionLabelSettings
The retention settings enforced on the item.
Response
If successful, this method returns a 200 OK
response code and an updated itemRetentionLabel object in the response body.
Examples
Request
The following example shows a request.
PATCH https://graph.microsoft.com/v1.0/drives/22e064df-3562-4a3c-98c3-74721ca06aa0/items/44d372fc-2eb6-4c85-8538-f3a0386a568f/retentionLabel
Content-Type: application/json
{
"retentionSettings": {
"isRecordLocked": true
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new ItemRetentionLabel
{
RetentionSettings = new RetentionLabelSettings
{
IsRecordLocked = true,
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Drives["{drive-id}"].Items["{driveItem-id}"].RetentionLabel.PatchAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc drives items retention-label patch --drive-id {drive-id} --drive-item-id {driveItem-id} --body '{\
"retentionSettings": {\
"isRecordLocked": true\
}\
}\
'
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewItemRetentionLabel()
retentionSettings := graphmodels.NewRetentionLabelSettings()
isRecordLocked := true
retentionSettings.SetIsRecordLocked(&isRecordLocked)
requestBody.SetRetentionSettings(retentionSettings)
retentionLabel, err := graphClient.Drives().ByDriveId("drive-id").Items().ByDriveItemId("driveItem-id").RetentionLabel().Patch(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
ItemRetentionLabel itemRetentionLabel = new ItemRetentionLabel();
RetentionLabelSettings retentionSettings = new RetentionLabelSettings();
retentionSettings.setIsRecordLocked(true);
itemRetentionLabel.setRetentionSettings(retentionSettings);
ItemRetentionLabel result = graphClient.drives().byDriveId("{drive-id}").items().byDriveItemId("{driveItem-id}").retentionLabel().patch(itemRetentionLabel);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const itemRetentionLabel = {
retentionSettings: {
isRecordLocked: true
}
};
await client.api('/drives/22e064df-3562-4a3c-98c3-74721ca06aa0/items/44d372fc-2eb6-4c85-8538-f3a0386a568f/retentionLabel')
.update(itemRetentionLabel);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\ItemRetentionLabel;
use Microsoft\Graph\Generated\Models\RetentionLabelSettings;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new ItemRetentionLabel();
$retentionSettings = new RetentionLabelSettings();
$retentionSettings->setIsRecordLocked(true);
$requestBody->setRetentionSettings($retentionSettings);
$result = $graphServiceClient->drives()->byDriveId('drive-id')->items()->byDriveItemId('driveItem-id')->retentionLabel()->patch($requestBody)->wait();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Files
$params = @{
retentionSettings = @{
isRecordLocked = $true
}
}
Update-MgDriveItemRetentionLabel -DriveId $driveId -DriveItemId $driveItemId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
from msgraph import GraphServiceClient
from msgraph.generated.models.item_retention_label import ItemRetentionLabel
from msgraph.generated.models.retention_label_settings import RetentionLabelSettings
graph_client = GraphServiceClient(credentials, scopes)
request_body = ItemRetentionLabel(
retention_settings = RetentionLabelSettings(
is_record_locked = True,
),
)
result = await graph_client.drives.by_drive_id('drive-id').items.by_drive_item_id('driveItem-id').retention_label.patch(request_body)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
The following example shows the response.
HTTP/1.1 200 OK
Content-Type: application/json
{
"name": "Retention label for Contracts",
"retentionSettings": {
"behaviorDuringRetentionPeriod": "retain",
"isDeleteAllowed": false,
"isRecordLocked": true,
"isMetadataUpdateAllowed": false,
"isContentUpdateAllowed": false,
"isLabelUpdateAllowed": false
},
"isLabelAppliedExplicitly": false,
"labelAppliedDateTime": "2022-12-22T10:18:23.6580555+00:00",
"labelAppliedBy": {
"user": {
"id": "56d171c8-a92e-4359-9c4a-38b88ac7eabd",
"displayName": "Contoso Admin"
}
}
}