Updating the metadata applied to a file or folder can be done by using the
item’s id, the template’s templateKey and scope, and a set of JSON
operations to manipulate the data on the template instance.
To update the metadata to a file, call the
PUT /files/:file_id/metadata/:scope/:templateKey API endpoint
with the file’s file_id, the template’s scope and templateKey, set of JSON
operations to manipulate the data on the template instance.
To update the metadata to a folder, call the
PUT /folders/:folder_id/metadata/:scope/:templateKey API
endpoint with the folder’s folder_id, the template’s scope and
templateKey, set of JSON operations to manipulate the data on the template instance.
Updating an piece of metadata follow the JSON-Patch specification,
which is represented as a list of operation objects.For metadata instances, these operations can be either add, replace,
remove , test, move, or copy. Every operation exists out of an op
name, the JSON Pointerpath that points to the field to changes,
and an optional value or from value depending on the operation being made.
When editing metadata, only values that adhere to the metadata template schema
will be accepted. The update is applied completely or not at all. If any
errors occur during the application of the update operations, the metadata
instance is not changed.The template instance can only be updated if the template has already been
assigned to the file or folder.
This will add the displayName field with a value that matches the value of the
name field. Before this operation, the template did not have a value for the
displayName field.
Report incorrect code
Copy
Ask AI
{ "name": "Model 3", "displayName": "Model 3", // new value, copied from the name "category": "SUVs", "$type": "productInfo-8120731a-41e4-11ea-b77f-2e728ce88125", "$parent": "folder_3456", "$id": "22ba8c96-41e6-11ea-b77f-2e728ce88125", "$version": 3, "$typeVersion": 0, "$template": "productInfo", "$scope": "enterprise_1234567", "$canEdit": true}
For enum and multiSelect fields this new value needs to be one of the
valid options for the field.
This will add the displayName field with a value that matches the value of the
name field. Before this operation, the template did not have a value for the
displayName field. After this operation, the name field no longer exists.
Report incorrect code
Copy
Ask AI
{ // "name": "Model 3", // old value, no longer present now "displayName": "Model 3", // new value, copied from the name "category": "SUVs", "$type": "productInfo-8120731a-41e4-11ea-b77f-2e728ce88125", "$parent": "folder_3456", "$id": "22ba8c96-41e6-11ea-b77f-2e728ce88125", "$version": 3, "$typeVersion": 0, "$template": "productInfo", "$scope": "enterprise_1234567", "$canEdit": true}
For enum and multiSelect fields this new value needs to be one of the
valid options for the field.
When a test fails the API will not perform any of the operations and return a
409 Conflict HTTP status with the following error.
Report incorrect code
Copy
Ask AI
{ "message": "value differs from expectations", "code": "failed_json_patch_application", "request_id": "bzxgr1gbcq5h67pj"}
The main purpose of this operation is to validate that the values on the
metadata instance are as expected before any operations are performed. The Box
API either performs all changes or none, and therefore a failing test is very
useful to ensure all values are expected before any transformation is applied.