Apply metadata to a file

Apply metadata to a file

With your new customerData template in hand you can now apply this template to a file or folder. To apply this template you will need the scope and templateKey of the template, as well as the ID of the item to apply the template to.

cURL
curl -X POST https://api.box.com/2.0/files/12345/metadata/enterprise/customerInfo \
    -H "authorization: Bearer <ACCESS_TOKEN>" \
    -H "content-type: application/json" \
    -d '{
      "name": "Box, Inc",
      "industry": "Technology",
      "tav": 1000000
    }'
.NET
var metadataValues = new Dictionary<string, object>()
{
    { "name", "Box, Inc" },
    { "industry", "Technology" },
    { "tav", 100000 }
};

Dictionary<string, object> metadata = await client.MetadataManager
    .CreateFileMetadataAsync(fileId: "12345", metadataValues, "enterprise", "customerInfo");
Java
BoxFile file = new BoxFile(api, "12345");

file.createMetadata(
    "customerInfo",
    "enterprise",
    new Metadata()
        .add("name", "Box, Inc")
        .add("industry", "Technology")
        .add("tav", 100000)
);
Python
metadata = {
    'name': 'Box, Inc',
    'industry': 'Technology',
    'tav': 1000000
}

client.file(file_id='11111').metadata(scope='enterprise', template='customerInfo').set(metadata)
Node
client.files.addMetadata(
    '12345',
    client.metadata.scopes.ENTERPRISE,
    "customerInfo",
    {
        name: "Box, Inc",
        industry: "Technology",
        tav: 1000000
    }
).then(metadata => {
    // ...
});

The industry field in this example is an enum field and therefore the value needs to be one of the available options on the field. Any other value will result in an error.

The API will return the newly created metadata instance.

{
  "name": "Box, Inc",
  "industry": "Technology",
  "tav": 1000000,
  "$id": "01234500-12f1-1234-aa12-b1d234cb567e",
  "$parent": "folder_12345,",
  "$scope": "enterprise_34567",
  "$template": "customerInfo",
  "$type": "customerInfo-6bcba49f-ca6d-4d2a-a758-57fe6edf44d0",
  "$typeVersion": 2,
  "$version": 1,
  "$canEdit": true
}