Apply metadata to an item
Apply metadata to an item
A metadata template can be applied to a file or folder using the item's id,
the template's templateKey and scope, and a set of values for each field in
the template.
Apply metadata to a file
To apply an instance of a metadata template to a file, call the
POST /files/:file_id/metadata/:scope/:templateKey API endpoint
with the file's file_id, the template's scope and templateKey, and an
optional set of values for each field in the template.
curl -i -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"
}'await client.fileMetadata.createFileMetadataById(
file.id,
'enterprise' as CreateFileMetadataByIdScope,
templateKey,
{
['name']: 'John',
['age']: 23,
['birthDate']: '2001-01-03T02:20:50.520Z',
['countryCode']: 'US',
['sports']: ['basketball', 'tennis'],
},
);client.file_metadata.create_file_metadata_by_id(
file.id,
CreateFileMetadataByIdScope.ENTERPRISE,
template_key,
{
"name": "John",
"age": 23,
"birthDate": "2001-01-03T02:20:50.520Z",
"countryCode": "US",
"sports": ["basketball", "tennis"],
},
)await client.FileMetadata.CreateFileMetadataByIdAsync(fileId: file.Id, scope: CreateFileMetadataByIdScope.Enterprise, templateKey: templateKey, requestBody: new Dictionary<string, object>() { { "name", "John" }, { "age", 23 }, { "birthDate", "2001-01-03T02:20:50.520Z" }, { "countryCode", "US" }, { "sports", Array.AsReadOnly(new [] {"basketball","tennis"}) } });try await client.fileMetadata.createFileMetadataById(fileId: file.id, scope: CreateFileMetadataByIdScope.global, templateKey: "properties", requestBody: ["abc": "xyz"])client.getFileMetadata().createFileMetadataById(file.getId(), CreateFileMetadataByIdScope.ENTERPRISE, templateKey, mapOf(entryOf("name", "John"), entryOf("age", 23), entryOf("birthDate", "2001-01-03T02:20:50.520Z"), entryOf("countryCode", "US"), entryOf("sports", Arrays.asList("basketball", "tennis"))))await client.FileMetadata.CreateFileMetadataByIdAsync(fileId: file.Id, scope: CreateFileMetadataByIdScope.Enterprise, templateKey: templateKey, requestBody: new Dictionary<string, object>() { { "name", "John" }, { "age", 23 }, { "birthDate", "2001-01-03T02:20:50.520Z" }, { "countryCode", "US" }, { "sports", Array.AsReadOnly(new [] {"basketball","tennis"}) } });await client.fileMetadata.createFileMetadataById(
file.id,
'enterprise' as CreateFileMetadataByIdScope,
templateKey,
{
['name']: 'John',
['age']: 23,
['birthDate']: '2001-01-03T02:20:50.520Z',
['countryCode']: 'US',
['sports']: ['basketball', 'tennis'],
},
);Apply metadata to a folder
To apply an instance of a metadata template to a folder, call the
POST /folders/:folder_id/metadata/:scope/:templateKey API endpoint
with the folder's folder_id, the template's scope and templateKey, and an
optional set of values for each field in the template.
curl -i -X POST "https://api.box.com/2.0/folders/4353455/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"
}'await client.folderMetadata.createFolderMetadataById(
folder.id,
'enterprise' as CreateFolderMetadataByIdScope,
templateKey,
{
['name']: 'John',
['age']: 23,
['birthDate']: '2001-01-03T02:20:50.520Z',
['countryCode']: 'US',
['sports']: ['basketball', 'tennis'],
},
);client.folder_metadata.create_folder_metadata_by_id(
folder.id,
CreateFolderMetadataByIdScope.ENTERPRISE,
template_key,
{
"name": "John",
"age": 23,
"birthDate": "2001-01-03T02:20:50.520Z",
"countryCode": "US",
"sports": ["basketball", "tennis"],
},
)await client.FolderMetadata.CreateFolderMetadataByIdAsync(folderId: folder.Id, scope: CreateFolderMetadataByIdScope.Enterprise, templateKey: templateKey, requestBody: new Dictionary<string, object>() { { "name", "John" }, { "age", 23 }, { "birthDate", "2001-01-03T02:20:50.520Z" }, { "countryCode", "US" }, { "sports", Array.AsReadOnly(new [] {"basketball","tennis"}) } });try await client.folderMetadata.createFolderMetadataById(folderId: folder.id, scope: CreateFolderMetadataByIdScope.global, templateKey: "properties", requestBody: ["abc": "xyz"])client.getFolderMetadata().createFolderMetadataById(folder.getId(), CreateFolderMetadataByIdScope.ENTERPRISE, templateKey, mapOf(entryOf("name", "John"), entryOf("age", 23), entryOf("birthDate", "2001-01-03T02:20:50.520Z"), entryOf("countryCode", "US"), entryOf("sports", Arrays.asList("basketball", "tennis"))))await client.FolderMetadata.CreateFolderMetadataByIdAsync(folderId: folder.Id, scope: CreateFolderMetadataByIdScope.Enterprise, templateKey: templateKey, requestBody: new Dictionary<string, object>() { { "name", "John" }, { "age", 23 }, { "birthDate", "2001-01-03T02:20:50.520Z" }, { "countryCode", "US" }, { "sports", Array.AsReadOnly(new [] {"basketball","tennis"}) } });await client.folderMetadata.createFolderMetadataById(
folder.id,
'enterprise' as CreateFolderMetadataByIdScope,
templateKey,
{
['name']: 'John',
['age']: 23,
['birthDate']: '2001-01-03T02:20:50.520Z',
['countryCode']: 'US',
['sports']: ['basketball', 'tennis'],
},
);Request body
The body of the request can contain a value for each field in the template. To inspect what fields are present on a template, inspect a metadata metadata template.
For example, let's assume the following template.
{
"id": "8120731a-41e4-11ea-b77f-2e728ce88125",
"type": "metadata_template",
"templateKey": "productInfo",
"scope": "enterprise_1234567",
"displayName": "Product Info",
"hidden": false,
"copyInstanceOnItemCopy": true,
"fields": [
{
"id": "feed71de-41e5-11ea-b77f-2e728ce88125",
"type": "string",
"key": "name",
"displayName": "Name",
"hidden": false
},
{
"id": "02b36bb6-41e6-11ea-b77f-2e728ce88125",
"type": "enum",
"key": "category",
"displayName": "Category",
"hidden": false,
"options": [
{
"id": "06a7bcc2-41e6-11ea-b77f-2e728ce88125",
"key": "SUVs"
},
{
"id": "0a50df02-41e6-11ea-b77f-2e728ce88125",
"key": "Saloons"
},
{
"id": "0e466be0-41e6-11ea-b77f-2e728ce88125",
"key": "Cabriolets"
}
]
}
]
}
This template has 2 template fields, name and category. The name
field is a regular text field, and the category is an enum.
The request body to assign this template to a file or folder can include a value for any of the fields on the template. It is possible for the body to have no values for no fields.
In this case, a valid example would be the following request body.
{
"name": "Model 3",
"category": "SUVs"
}