Tools for creating and managing metadata templates and instances in Box.
from box_ai_agents_toolkit import box_metadata_template_create
template = box_metadata_template_create(
client,
scope="enterprise",
display_name="My Template",
template_key="tmpl1",
hidden=True,
fields=[{"key": "a", "type": "string"}],
copy_instance_on_item_copy=False,
)
print("Created Metadata Template:", template)from box_ai_agents_toolkit import box_metadata_template_get_by_key
template = box_metadata_template_get_by_key(client, scope="enterprise", template_key="tmpl1")
print("Metadata Template Details:", template)from box_ai_agents_toolkit import box_metadata_template_get_by_id
template = box_metadata_template_get_by_id(client, template_id="12345")
print("Metadata Template Details:", template)from box_ai_agents_toolkit import box_metadata_template_get_by_name
template = box_metadata_template_get_by_name(client, template_name="My Template", scope="enterprise")
print("Metadata Template Details:", template)Apply metadata to a file using a template.
from box_ai_agents_toolkit import box_metadata_set_instance_on_file
metadata = {"field1": "value1", "field2": "value2"}
result = box_metadata_set_instance_on_file(
client,
file_id="12345",
scope="enterprise",
template_key="tmpl1",
metadata=metadata
)
print("Metadata set:", result)Retrieve metadata from a file.
from box_ai_agents_toolkit import box_metadata_get_instance_on_file
metadata = box_metadata_get_instance_on_file(
client,
file_id="12345",
scope="enterprise",
template_key="tmpl1"
)
print("File metadata:", metadata)Update existing metadata on a file using JSON Patch operations.
from box_ai_agents_toolkit import box_metadata_update_instance_on_file
updates = [
{"op": "replace", "path": "/field1", "value": "new_value1"},
{"op": "add", "path": "/field3", "value": "value3"}
]
result = box_metadata_update_instance_on_file(
client,
file_id="12345",
scope="enterprise",
template_key="tmpl1",
request_body=updates
)
print("Metadata updated:", result)Remove metadata from a file.
from box_ai_agents_toolkit import box_metadata_delete_instance_on_file
box_metadata_delete_instance_on_file(
client,
file_id="12345",
scope="enterprise",
template_key="tmpl1"
)
print("Metadata instance deleted")box_api_metadata_template.py- Metadata template operations