Skip to main content
Question

Classification label

  • May 22, 2025
  • 3 replies
  • 42 views

Forum|alt.badge.img

On 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)

3 replies

Forum|alt.badge.img

 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!


Forum|alt.badge.img

Super, Thanks Willer. You are such a life saver.

 

Another followup question. How do I update the classification on a file ?  Also how do I list all the classifications defined in our BOX environment ?

 

Thanks Again

 

Appreciated

 

Shynee


Forum|alt.badge.img

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'])