Applies an instance of a metadata template to a file.
In most cases only values that are present in the metadata template
will be accepted, except for the global.properties
template which accepts
any key-value pair.
12345
The unique identifier that represent a file.
The ID for any file can be determined
by visiting a file in the web application
and copying the ID from the URL. For example,
for the URL https://*.app.box.com/files/123
the file_id
is 123
.
global
The scope of the metadata template
Value is one of global
,enterprise
properties
The name of the metadata template
Aaron Levie
A value for each of the fields that are present on the metadata template.
For the global.properties
template this can be an a list of zero
or more fields, as this template allows for any generic key-value
pairs to be stored on the template.
Returns the instance of the template that was applied to the file, including the data that was applied to the template.
Returns an error when the request body is not valid.
schema_validation_failed
- The request body contains a value for a for
a field that either does not exist, or for which the value or type does
not match the expected field type. An example might be an unknown option
for an enum
or multiSelect
field.Returns an error when the file or metadata template could not be found.
not_found
- The file could not be found, or the user does not have
access to the file.instance_tuple_not_found
- The metadata template could not be found.Returns an error when an instance of this metadata template is already present on the file.
tuple_already_exists
- An instance of them metadata template already
exists on the file.An unexpected client error.
curl -X POST https://api.box.com/2.0/files/12345/metadata/enterprise_27335/blueprintTemplate \
-H 'Authorization: Bearer <ACCESS_TOKEN>'
-H 'Content-Type: application/json" '
-d '{
"audience: "internal",
"documentType": "Q1 plans",
"competitiveDocument": "no",
"status": "active",
"author": "Jones",
"currentState": "proposal"
}'
var metadataValues = new Dictionary<string, object>()
{
{ "audience", "internal" },
{ "documentType", "Q1 plans" },
{ "competitiveDocument", "no" },
{ "status", "active" },
{ "author": "M. Jones" },
{ "currentState": "proposal" }
};
Dictionary<string, object> metadata = await client.MetadataManager
.CreateFileMetadataAsync(fileId: "11111", metadataValues, "enterprise", "marketingCollateral");
// Add property "foo" with value "bar" to the default metadata properties
BoxFile file = new BoxFile(api, "id");
file.createMetadata(new Metadata().add("/foo", "bar"));
metadata = {
'foo': 'bar',
'baz': 'quux',
}
applied_metadata = client.file(file_id='11111').metadata().create(metadata)
print('Applied metadata in instance ID {0}'.format(applied_metadata['$id']))
var metadataValues = {
audience: "internal",
documentType: "Q1 plans",
competitiveDocument: "no",
status: "active",
author: "Jones",
currentState: "proposal"
};
client.files.addMetadata('11111', client.metadata.scopes.ENTERPRISE, "marketingCollateral", metadataValues)
.then(metadata => {
/* metadata -> {
audience: 'internal',
documentType: 'Q1 plans',
competitiveDocument: 'no',
status: 'active',
author: 'Jones',
currentState: 'proposal',
'$type': 'marketingCollateral-d086c908-2498-4d3e-8a1f-01e82bfc2abe',
'$parent': 'file_11111',
'$id': '2094c584-68e1-475c-a581-534a4609594e',
'$version': 0,
'$typeVersion': 0,
'$template': 'marketingCollateral',
'$scope': 'enterprise_12345' }
*/
});
let metadata = [
"name": "John Doe",
"birthday": "2000-01-01T00:00:00Z",
"department": "Sales"
]
client.metadata.create(
forFileWithId: "11111",
scope: "enterprise",
templateKey: "personnelRecord",
keys: metadata
) { (result: Result<MetadataObject, BoxSDKError>) in
guard case let .success(metadata) = result {
print("Error adding metadata")
return
}
print("Successfully attached metadata")
}