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.
- Classifications
- 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 MetadataManager.CreateMetadataTemplate(BoxMetadataTemplate metadataTemplate)
method.
var field = new BoxMetadataTemplateField
{
DisplayName = "Classification",
Type = "enum",
Key = "Box_Security_Classification_Key",
Options = new List<BoxMetadataTemplateFieldOption>()
{
new BoxMetadataTemplateFieldOption
{
Key = "Classified"
}
}
};
var metadataTemplate = new BoxMetadataTemplate
{
DisplayName = "Classification",
TemplateKey = "securityClassification-6VMVochwUWo",
Scope = "enterprise",
Fields = new List<BoxMetadataTemplateField>() { field },
};
var template = await client.MetadataManager.CreateMetadataTemplate(metadataTemplate);
To retrieve a list of all the classifications in an enterprise call the
MetadataManager.GetMetadataTemplate(string scope, string template)
method to get the classifications template, which will contain a list of all the
classifications.
var template = await client.MetadataManager.GetMetadataTemplate("enterprise", "securityClassification-6VMVochwUWo");
To add another classification, call the
MetadataManager.UpdateMetadataTemplate(IEnumerable<BoxMetadataTemplateUpdate> metadataTemplateUpdate, string scope, string template)
method
with proper parameters.
var update = new BoxMetadataTemplateUpdate
{
Op = MetadataTemplateUpdateOp.addEnumOption,
FieldKey = "Box_Security_Classification_Key",
Data = new
{
key = "Sensitive"
}
};
var template = await client.MetadataManager
.UpdateMetadataTemplate(new List<BoxMetadataTemplateUpdate>() { update }, "enterprise", "securityClassification-6VMVochwUWo");
To update a classification, call the
MetadataManager.UpdateMetadataTemplate(IEnumerable<BoxMetadataTemplateUpdate> metadataTemplateUpdate, string scope, string template)
method
with proper parameters.
var update = new BoxMetadataTemplateUpdate
{
Op = MetadataTemplateUpdateOp.editEnumOption,
FieldKey = "Box_Security_Classification_Key",
EnumOptionKey = "Sensitive",
Data = new
{
key = "Very Sensitive"
}
};
var template = await client.MetadataManager
.UpdateMetadataTemplate(new List<BoxMetadataTemplateUpdate>() { update }, "enterprise", "securityClassification-6VMVochwUWo");
To add a classification to a file, call
MetadataManager.SetFileMetadataAsync(string fileId, Dictionary<string, object> metadata, string scope, string template)
with the name of the classification template, as well as the details of the classification
to add to the file.
var fileId = "0";
var classification = new Dictionary<string, object>
{
{ "Box_Security_Classification_Key", "Sensitive" }
};
var classificationData = await client.MetadataManager.SetFileMetadataAsync(fileId, classification, "enterprise", "securityClassification-6VMVochwUWo");
To update a classification on a file, call
MetadataManager.UpdateFileMetadataAsync(string fileId, List<BoxMetadataUpdate> updates, string scope, string template)
with the name of the classification template, as well as the details of the classification
to add to the file.
var fileId = "0";
var update = new BoxMetadataUpdate
{
Op = MetadataUpdateOp.replace,
Path = "/Box_Security_Classification_Key",
Value = "Very Sensitive"
};
var classificationData = await client.MetadataManager
.UpdateFileMetadataAsync(fileId, new List<BoxMetadataUpdate>() { update }, "enterprise", "securityClassification-6VMVochwUWo");
Retrieve the classification on a file by calling
MetadataManager.GetFileMetadataAsync(string fileId, string scope, string template)
on a file.
var fileId = "0";
var fileMetadata = await client.MetadataManager.GetFileMetadataAsync(fileId, "enterprise", "securityClassification-6VMVochwUWo");
A classification can be removed from a file by calling
MetadataManager.DeleteFileMetadataAsync(string fileId, string scope, string template)
.
var fileId = "0";
var fileMetadata = await client.MetadataManager.DeleteFileMetadataAsync(fileId, "enterprise", "securityClassification-6VMVochwUWo");
To add a classification to a folder, call
MetadataManager.SetFolderMetadataAsync(string folderId, Dictionary<string, object> metadata, string scope, string template)
with the name of the classification template, as well as the details of the classification
to add to the folder.
var folderId = "0";
var classification = new Dictionary<string, object>
{
{ "Box_Security_Classification_Key", "Sensitive" }
};
var classificationData = await client.MetadataManager.SetFolderMetadataAsync(folderId, classification, "enterprise", "securityClassification-6VMVochwUWo");
To update a classification on a folder, call
MetadataManager.UpdateFolderMetadataAsync(string folderId, List<BoxMetadataUpdate> updates, string scope, string template)
.
with the name of the classification template, as well as the details of the classification
to add to the folder.
var folderId = "0";
var update = new BoxMetadataUpdate
{
Op = MetadataUpdateOp.replace,
Path = "/Box_Security_Classification_Key",
Value = "Very Sensitive"
};
var classificationData = await client.MetadataManager
.UpdateFolderMetadataAsync(folderId, new List<BoxMetadataUpdate>(){ update }, "enterprise", "securityClassification-6VMVochwUWo");
Retrieve the classification on a folder by calling
MetadataManager.GetFolderMetadataAsync(string folderId, string scope, string template)
on a folder.
var folderId = "0";
var folderMetadata = await client.MetadataManager.GetFolderMetadataAsync(folderId, "enterprise", "securityClassification-6VMVochwUWo");
A classification can be removed from a folder by calling
MetadataManager.DeleteFolderMetadataAsync(string folderId, string scope, string template)
.
var folderId = "0";
var folderMetadata = await client.MetadataManager.DeleteFolderMetadataAsync(folderId, "enterprise", "securityClassification-6VMVochwUWo");