Get a metadata template

Get a metadata template

Information for a metadata template can be retrieved using the template's name and scope, or the template's identifier.

The authenticated user can only get Information about metadata templates scoped within the global scope or the enterprise_:id scope where :id is the ID of their enterprise.

Get a metadata template by name

To get a metadata template by name, call the GET /metadata_templates/:scope/:templateKey/schema API endpoint with the template's scope and templateKey.

cURL
curl -i -X GET "https://api.box.com/2.0/metadata_templates/enterprise/blueprintTemplate/schema" \
     -H "authorization: Bearer <ACCESS_TOKEN>"
TypeScript Gen
await client.metadataTemplates.getMetadataTemplate(
  'enterprise' as GetMetadataTemplateScope,
  template.templateKey!,
);
Python Gen
client.metadata_templates.get_metadata_template(
    GetMetadataTemplateScope.ENTERPRISE, template.template_key
)
.NET Gen
await client.MetadataTemplates.GetMetadataTemplateAsync(scope: GetMetadataTemplateScope.Enterprise, templateKey: NullableUtils.Unwrap(template.TemplateKey));
Swift Gen (Beta)
try await client.metadataTemplates.getMetadataTemplate(scope: GetMetadataTemplateScope.enterprise, templateKey: template.templateKey!)
Java
MetadataTemplate template = MetadataTemplate.getMetadataTemplate(api, "templateName");
Python
template = client.metadata_template('enterprise', 'employeeRecord').get()
print(f'The {template.displayName} template has {len(template.fields)} fields')
.NET
BoxMetadataTemplate template = await client.MetadataManager
    .GetMetadataTemplate("enterprise", "marketingCollateral");
Node
client.metadata.getTemplateSchema('enterprise', 'vcontract')
	.then(template => {
		/* template -> {
			id: '17f2d715-6acb-45f2-b96a-28b15efc9faa',
			templateKey: 'vcontract',
			scope: 'enterprise_12345',
			displayName: 'Vendor Contract',
			hidden: true,
			fields: 
			[ { type: 'date',
				key: 'signed',
				displayName: 'Date Signed',
				hidden: false },
				{ type: 'string',
				key: 'vendor',
				displayName: 'Vendor',
				hidden: false },
				{ type: 'enum',
				key: 'fy',
				displayName: 'Fiscal Year',
				options: 
					[ { key: 'FY17' },
					{ key: 'FY18' },
					{ key: 'FY19' } ],
				hidden: false } ] }
		*/
	});
iOS
client.metadata.getTemplateByKey(
    scope: "enterprise",
    templateKey: "personnelRecord"
) { (result: Result<MetadataTemplate, BoxSDKError>) in
    guard case let .success(template) = result {
        print("Error retrieving metadata template")
        return
    }

    print("Metadata template has \(template.fields?.count) fields")
}

To get the scope and templateKey for a template, either list all metadata templates, or list all instances on an item.

Get a metadata template by ID

To get a metadata template by ID, you will need to pass the template's id to the GET /metadata_templates/:id API endpoint.

cURL
curl -i -X GET "https://api.box.com/2.0/metadata_templates/d9671692-3df6-11ea-b77f-2e728ce88125" \
     -H "authorization: Bearer <ACCESS_TOKEN>"
TypeScript Gen
await client.metadataTemplates.getMetadataTemplateById(template.id);
Python Gen
client.metadata_templates.get_metadata_template_by_id(template.id)
.NET Gen
await client.MetadataTemplates.GetMetadataTemplateByIdAsync(templateId: template.Id);
Swift Gen (Beta)
try await client.metadataTemplates.getMetadataTemplateById(templateId: template.id)
Java
MetadataTemplate template = MetadataTemplate.getMetadataTemplateByID(api, "37c0204b-3fe1-4a32-b9da-f28e88f4c4c6");
Python
template = client.metadata_template_by_id(template_id='abcdef-fba434-ace44').get()
print(f'The {template.displayName} template has {len(template.fields)} fields')
.NET
BoxMetadataTemplate template = await client.MetadataManager
    .GetMetadataTemplateById("17f2d715-6acb-45f2-b96a-28b15efc9faa");
Node
client.metadata.getTemplateByID('17f2d715-6acb-45f2-b96a-28b15efc9faa')
	.then(template => {
		/* template -> {
			id: '17f2d715-6acb-45f2-b96a-28b15efc9faa',
			templateKey: 'vcontract',
			scope: 'enterprise_12345',
			displayName: 'Vendor Contract',
			hidden: true,
			fields: 
			[ { type: 'date',
				key: 'signed',
				displayName: 'Date Signed',
				hidden: false },
				{ type: 'string',
				key: 'vendor',
				displayName: 'Vendor',
				hidden: false },
				{ type: 'enum',
				key: 'fy',
				displayName: 'Fiscal Year',
				options: 
					[ { key: 'FY17' },
					{ key: 'FY18' },
					{ key: 'FY19' } ],
				hidden: false } ] }
		*/
	});
iOS
client.metadata.getTemplateById(
    id: "26004e29-7b94-44a1-8a63-f9aa384c7421"
) { (result: Result<MetadataTemplate, BoxSDKError>) in
    guard case let .success(template) = result {
        print("Error retrieving metadata template")
        return
    }

    print("Metadata template has \(template.fields?.count) fields")
}

To get the id for a template, either list all metadata templates, or list all instances on an item.