Classifications are a type of metadata that allows users and applications to define and assign a content classification to files and folders.
Classifications use the metadata APIs to add and remove classifications, and assign them to files. For more details on metadata templates please see the metadata documentation.
- Add initial classifications
- List all classifications
- Add another classification
- Update a classification
- Delete a classification
- Delete all classifications
- Add classification to file
- Update classification on file
- Get classification on file
- Remove classification from file
- Add classification to folder
- Update classification on folder
- Get classification on folder
- Remove classification from folder
If an enterprise does not already have a classification defined, the first classification(s)
can be added with the
client.create_metadata_template(display_name, fields, template_key=None, hidden=False, scope='enterprise')
](https://box-python-sdk.readthedocs.io/en/latest/boxsdk.client.html#boxsdk.client.client.Client.create_metadata_template)
method.
from boxsdk.object.metadata_template import MetadataField, MetadataFieldType
fields = [
MetadataField(MetadataFieldType.ENUM, 'Classification', key='Box__Security__Classification__Key', options=['Top Secret'])
]
template = client.create_metadata_template('Classification', fields, template_key='securityClassification-6VMVochwUWo')
To retrieve a list of all the classifications in an enterprise call the
client.metadata_template(scope, template_key)
method to get the classifications template, which will contain a list of all the
classifications.
template = client.metadata_template('enterprise', 'securityClassification-6VMVochwUWo').get()
To add another classification, call the
template.start_update()
API to start making changes to the
template, and then call the template.update_info(updates=new_updates)
with the changes to apply to the template.
template = client.metadata_template('enterprise', 'securityClassification-6VMVochwUWo')
new_updates = template.start_update()
new_updates.add_enum_option('Box__Security__Classification__Key', 'Sensitive')
updated_template = template.update_info(updates=new_updates)
To update a classification, call the
template.start_update()
API to start making changes to the
template, and then call the template.update_info(updates=new_updates)
with the classification to change on the template.
template = client.metadata_template('enterprise', 'securityClassification-6VMVochwUWo')
new_updates = template.start_update()
new_updates.edit_enum_option('Box__Security__Classification__Key', 'Sensitive', 'Very Sensitive')
updated_template = template.update_info(updates=new_updates)
To add a classification to a file, call
file.metadata(scope='global', template='properties')
with the name of the classification template, as well as the details of the classification
to add to the file.
classification = {
'Box__Security__Classification__Key': 'Sensitive',
}
applied_metadata = client.file(file_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').set(classification)
To update a classification on a file, call
file.metadata(scope='global', template='properties')
with the name of the classification template, as well as the details of the classification
to add to the file.
classification = {
'Box__Security__Classification__Key': 'Sensitive',
}
applied_metadata = client.file(file_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').set(classification)
Retrieve the classification on a file by calling
file.metadata(scope='global', template='properties').get()
on a file.
metadata = client.file(file_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').get()
A classification can be removed from a file by calling
file.metadata(scope='global', template='properties').delete()
.
client.file(file_id='11111').metadata(scope='securityClassification-6VMVochwUWo', template='myMetadata').delete()
To add a classification to a folder, call
folder.metadata(scope='global', template='properties')
with the name of the classification template, as well as the details of the classification
to add to the folder.
classification = {
'Box__Security__Classification__Key': 'Sensitive',
}
applied_metadata = client.folder(folder_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').set(classification)
To update a classification on a folder, call
folder.metadata(scope='global', template='properties')
with the name of the classification template, as well as the details of the classification
to add to the folder.
classification = {
'Box__Security__Classification__Key': 'Sensitive',
}
applied_metadata = client.folder(folder_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').set(classification)
Retrieve the classification on a folder by calling
folder.metadata(scope='global', template='properties').get()
on a folder.
metadata = client.folder(folder_id='11111').metadata(scope='enterprise', template='securityClassification-6VMVochwUWo').get()
A classification can be removed from a folder by calling
folder.metadata(scope='global', template='properties').delete()
.
client.folder(folder_id='11111').metadata(scope='securityClassification-6VMVochwUWo', template='myMetadata').delete()