Classification label
AnsweredOn Each file I see classification label from the web interface. But it doesn't list it through API call. How do I access this tag through python sdk ? Also how do I list all the classification labels ?
I only get these tags from the API call
type
id
file_version
sequence_id
etag
sha1
name
description
size
path_collection
created_at
modified_at
trashed_at
purged_at
content_created_at
content_modified_at
created_by
modified_by
owned_by
shared_link
parent
item_status
Here is the code
sdk = JWTAuth(
client_id="super secret client id",
client_secret="super secret",
enterprise_id="enterprise_id",
jwt_key_id="key_id",
rsa_private_key_file_sys_path="private.pem",
)
client = Client(sdk)
user = client.user(user_id=***phone number removed for privacy***')
for item in (client.as_user(user).file(file_id=***number removed for privacy***111).get()):
print(item)
-
The Classification information is contained within special metadata on the file. You can access it like this:
file = client.file(file_id).get(fields=['metadata.enterprise.securityClassification-6VMVochwUWo']) classification = file.metadata['enterprise']['securityClassification-6VMVochwUWo']['Box__Security__Classification__Key']
Also, I'll add an item to our team's backlog to make this a bit easier in the SDK!
-
Here are some python SDK code examples for you:
Add classification:
classification_metadata = {
'Box__Security__Classification__Key': 'Public',
}
template_key = 'securityClassification-6VMVochwUWo'
applied_metadata = client.file(file_id).metadata('enterprise', template_key).create(classification_metadata)Update classification:
template_key = 'securityClassification-6VMVochwUWo'classification_metadata = client.file(file_id).metadata('enterprise', template_key)
updates = classification_metadata.start_update()
updates.update('/Box__Security__Classification__Key', 'Internal')
classification_metadata.update(updates)Get a list of classification values:
template_key = 'securityClassification-6VMVochwUWo'
field_key = 'Box__Security__Classification__Key'
classification_template = client.metadata_template('enterprise', template_key).get()
print('Available Classification values:')
for field in classification_template.fields:
if field['key'] == field_key:
for option in field['options']:
print(option['key'])
Please sign in to leave a comment.
Comments
3 comments