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"
}'
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"
}'
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"
}