This document describes how to perform these tasks involving labels:
- Disable a label
- Enable a label
- Delete a label
Disable a label
Disabling a label results in a new disabled published revision based on the current published revision. If there's a draft revision, a new disabled draft revision is created based on the latest draft revision. Older draft revisions are deleted. For more information, see Label lifecycle.
Once disabled, users can still apply this label through the Google Drive Labels API. The label still appears where it's already been applied and in your search results. A disabled label can be deleted.
To disable a published label, use the
disable method on
the labels resource.
You also must specify:
A
labelsresource that represents the label. It contains anameand anid, which is a globally unique identifier for the label.The
useAdminAccessquery parameter is set totrueto use the user's administrator credentials. Before allowing access, the server verifies that the user has the required Manage Classification Labels administrator privileges.
The following code sample shows how to use the label's id to disable the
correct label:
Python
service.labels().disable(
name='labels/ID',
body={
'useAdminAccess': True
}
).execute()
Node.js
service.labels.disable({
name: 'labels/ID',
requestBody: {
useAdminAccess: true
}
}, (err, res) => {
if (err) return console.error('The API returned an error: ' + err);
console.log(res);
});
Replace ID with the ID of the label to disable.
The label has the
State of DISABLED
and the label's revision ID is incremented. Users can apply the label through
the Drive Labels API. However, a disabled label isn't shown in a UI unless
the
showInApply
field of the
DisabledPolicy
object is configured.
Enable a label
Enabling a disabled label restores it to its published state. It results in a new published revision based on the current disabled published revision. If there's an existing disabled draft revision, a new revision is created based on that draft and is enabled. For more information, see Label lifecycle.
To enable a disabled label, use the
enable method on
the labels resource.
You also must specify:
A
labelsresource that represents the label. It contains anameand anid, which is a globally unique identifier for the label.The
useAdminAccessquery parameter is set totrueto use the user's administrator credentials. Before allowing access, the server verifies that the user has the required Manage Classification Labels administrator privileges.
The following code sample shows how to use the label's id to enable the
correct label:
Python
service.labels().enable(
name='labels/ID',
body={
'useAdminAccess': True
}
).execute()
Node.js
service.labels.enable({
name: 'labels/ID',
requestBody: {
useAdminAccess: true
}
}, (err, res) => {
if (err) return console.error('The API returned an error: ' + err);
console.log(res);
});
Replace ID with the ID of the label to enable.
The label has the
State of PUBLISHED
and the label's revision ID is incremented. Users can view and apply the label
to files through the Drive Labels API.
Delete a label
Only draft and disabled labels can be deleted. When a label is deleted, all instances where the label was previously applied, including any corresponding field values entered by users, are permanently deleted and removed from those Drive files.
To delete a label, you must first disable it and then use the
delete method on
the labels resource.
You also must specify:
A
labelsresource that represents the label. It contains anameand anid, which is a globally unique identifier for the label.The
useAdminAccessquery parameter is set totrueto use the user's administrator credentials. Before allowing access, the server verifies that the user has the required Manage Classification Labels administrator privileges.
The following code sample shows how to use the label's id to delete the
correct label:
Python
response = service.labels().delete(
name='labels/ID',
useAdminAccess=True
).execute()
Node.js
service.labels.delete({
name: 'labels/ID',
useAdminAccess: true
}, (err, res) => {
if (err) return console.error('The API returned an error: ' + err);
console.log(res);
});
Replace ID with the ID of the label to delete.
The label has the
State of DELETED
and the label's revision ID is incremented. The label cannot be applied and
deleted labels are eventually purged. For more information, see Label
lifecycle.