Manage Applications

    Create metadata template

    post
    https://api.box.com/2.0
    /metadata_templates/schema

    Creates a new metadata template that can be applied to files and folders.

    Request

    application/json

    Request Body

    stringin bodyoptional
    Product Info4096

    The display name of the template

    Metadata Template Field arrayin bodyoptional

    The ordered set of key:value pairs for the template.

    booleanin bodyoptional
    truefalse

    Whether this template is hidden in the UI

    stringin bodyoptional
    enterprise_123456

    The scope of the object. global and enterprise_* scopes are supported.

    The global scope contains the template with a key of properties, while the enterprise scope pertains to custom templates created within the enterprise.

    The ID of the enterprise will be appended to the enterprise scope.

    stringin bodyoptional
    productInfo64

    A unique identifier for the template. The identifier must be unique across the scope of the enterprise to which the metadata template is being applied.

    Response

    application/jsonMetadata Template

    The schema representing the metadata template created.

    application/jsonClient Error

    Request body contains an invalid metadata schema.

    application/jsonClient Error

    Request body contains a scope that the user is not allowed to create a template for.

    You can now try out some of our APIs live, right here in the documentation.
    Log In

    Request Example

    cURL
    curl -X POST https://api.box.com/2.0/metadata_templates/schema \
         -H "Authorization: Bearer <ACCESS_TOKEN>" \
         -H "Content-Type: application/json" \
         -d '{
          "templateKey": "customer",
          "scope": "enterprise",
          "displayName": "Customer",
          "fields": [
            {
              "type": "string",
              "key": "customerTeam",
              "displayName": "Customer team"
            },
            {
              "type": "string",
              "key": "category",
              "displayName": "Category"
            },
            {
              "type": "string",
              "key": "brand",
              "displayName": "Brand"
            },
            {
              "type": "multiSelect",
              "key": "fy",
              "displayName": "FY",
              "options": [
                {"key": "FY11"},
                {"key": "FY12"},
                {"key": "FY13"},
                {"key": "FY14"},
                {"key": "FY15"}
              ]
            },
            {
              "type": "enum",
              "key": "qtr",
              "displayName": "Qtr",
              "options": [
                {"key": "First"},
                {"key": "Second"},
                {"key": "Third"},
                {"key": "Fourth"}
              ]
            }
          ]
         }'
    .NET
    var templateParams = new BoxMetadataTemplate()
    {
        TemplateKey = "marketingCollateral",
        DisplayName = "Marketing Collateral",
        Scope = "enterprise",
        Fields = new List<BoxMetadataTemplateField>()
        {
            new BoxMetadataTemplateField()
            {
                Type = "enum",
                Key = "audience",
                DisplayName = "Audience",
                Options = new List<BoxMetadataTemplateFieldOption>()
                {
                    new BoxMetadataTemplateFieldOption() { Key = "internal" },
                    new BoxMetadataTemplateFieldOption() { Key = "external" }
                }
            },
            new BoxMetadataTemplateField()
            {
                Type = "string",
                Key = "author",
                DisplayName = "Author"
            }
        }
    };
    BoxMetadataTemplate template = await client.MetadataManager.CreateMetadataTemplate(templateParams);
    Java
    MetadataTemplate.Field metadataField = new MetadataTemplate.Field();
    metadataField.setType("string");
    metadataField.setKey("text");
    metadataField.setDisplayName("Text");
    
    List<MetadataTemplate.Field> fields = new ArrayList<MetadataTemplate.Field>();
    fields.add(metadataField);
    
    MetadataTemplate template = MetadataTemplate.createMetadataTemplate(api, "enterprise", "CustomField", "Custom Field", false, fields);
    
    final JsonObject jsonObject = new JsonObject();
    jsonObject.add("text", "This is a test text");
    
    Metadata metadata = new Metadata(jsonObject);
    boxFile.createMetadata("CustomField", metadata);
    Python
    from boxsdk.object.metadata_template import MetadataField, MetadataFieldType
    
    fields = [
        MetadataField(MetadataFieldType.STRING, 'Name')
        MetadataField(MetadataFieldType.DATE, 'Birthday', 'bday')
        MetadataField(MetadataFieldType.ENUM, 'State', options=['CA', 'TX', 'NY'])
    ]
    template = client.create_metadata_template('Employee Record', fields, hidden=True)
    print('Metadata template ID {0}/{1} created!'.format(template.scope, template.templateKey))
    Node
    // Create a new template, but hide it for now until it's ready for use
    client.metadata.createTemplate(
    		'Vendor Contract',
    		[
    			{
    				type: 'date',
    				key: 'signed',
    				displayName: 'Date Signed'
    			},
    			{
    				type: 'string',
    				key: 'vendor',
    				displayName: 'Vendor'
    			},
    			{
    				type: 'enum',
    				key: 'fy',
    				displayName: 'Fiscal Year',
    				options: [
    					{key: 'FY17'},
    					{key: 'FY18'},
    					{key: 'FY19'}
    				]
    			}
    		],
    		{
    			hidden: true,
    			templateKey: '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 } ] }
    		*/
    	});

    Response Example

    {
      "scope": "enterprise_123456",
      "templateKey": "productInfo",
      "displayName": "Product Info",
      "hidden": true,
      "fields": [
        {
          "type": "string",
          "key": "category",
          "displayName": "Category",
          "description": "The category",
          "hidden": true,
          "options": [
            {
              "id": "f7a9895f",
              "key": "category1"
            }
          ]
        }
      ],
      "id": "f7a9891f"
    }