> ## Documentation Index
> Fetch the complete documentation index at: https://developer.box.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a metadata template

export const Link = ({href, children, className, ...props}) => {
  const [localizedHref, setLocalizedHref] = useState(href);
  const supportedLocales = useMemo(() => ['ja'], []);
  useEffect(() => {
    const getLocaleFromPath = path => {
      const match = path.match(/^\/([a-z]{2})(?:\/|$)/);
      if (match) {
        const potentialLocale = match[1];
        if (supportedLocales.includes(potentialLocale)) {
          return potentialLocale;
        }
      }
      return null;
    };
    const hasLocalePrefix = path => {
      const match = path.match(/^\/([a-z]{2})(?:\/|$)/);
      return match ? supportedLocales.includes(match[1]) : false;
    };
    const currentPath = window.location.pathname;
    const currentLocale = getLocaleFromPath(currentPath);
    if (href && href.startsWith('/') && !hasLocalePrefix(href)) {
      if (currentLocale) {
        setLocalizedHref(`/${currentLocale}${href}`);
      } else {
        setLocalizedHref(href);
      }
    } else {
      setLocalizedHref(href);
    }
  }, [href, supportedLocales]);
  return <a href={localizedHref} className={className} {...props}>
      {children}
    </a>;
};

export const MultiRelatedLinks = ({sections = []}) => {
  if (!sections || sections.length === 0) {
    return null;
  }
  return <div className="space-y-8">
      {sections.map((section, index) => <RelatedLinks key={index} title={section.title} items={section.items} />)}
    </div>;
};

export const RelatedLinks = ({title, items = []}) => {
  const getBadgeClass = badge => {
    if (!badge) return "badge-default";
    const badgeType = badge.toLowerCase().replace(/\s+/g, "-");
    return `badge-${badge === "ガイド" ? "guide" : badgeType}`;
  };
  if (!items || items.length === 0) {
    return null;
  }
  return <div className="my-8">
      {}
      <h3 className="text-sm font-bold uppercase tracking-wider mb-4">{title}</h3>

      {}
      <div className="flex flex-col gap-3">
        {items.map((item, index) => <a key={index} href={item.href} className="py-2 px-3 rounded related_link hover:bg-[#f2f2f2] dark:hover:bg-[#111827] flex items-center gap-3 group no-underline hover:no-underline border-b-0">
            {}
            <span className={`px-2 py-1 rounded-full text-xs font-semibold uppercase tracking-wide flex-shrink-0 ${getBadgeClass(item.badge)}`}>
              {item.badge}
            </span>

            {}
            <span className="text-base">{item.label}</span>
          </a>)}
      </div>
    </div>;
};

<RelatedLinks
  title="REQUIRED GUIDES"
  items={[
  { label: "Metadata template scopes", href: "/guides/metadata/scopes", badge: "GUIDE" },
  { label: "Create a metadata template", href: "/guides/metadata/templates/create", badge: "GUIDE" }
]}
/>

Updating a metadata template can be achieved by passing an array of operations
to the <Link href="/reference/put-metadata-templates-id-id-schema">`PUT /metadata_templates/:scope/:templateKey/schema`</Link> API.

<CodeGroup>
  ```sh cURL theme={null}
  curl -i -X PUT "https://api.box.com/2.0/metadata_templates/enterprise/blueprintTemplate/schema" \
       -H "authorization: Bearer <ACCESS_TOKEN>" \
       -H "content-type: application/json-patch+json" \
       -d '[
         {
           "op": "editField",
           "fieldKey": "category",
           "data": {
             "displayName": "Customer Group"
           }
         }
       ]'
  ```

  ```typescript Node/TypeScript v10 theme={null}
  await client.metadataTemplates.updateMetadataTemplate(
    'enterprise' as UpdateMetadataTemplateScope,
    templateKey,
    [
      {
        op: 'addField' as UpdateMetadataTemplateRequestBodyOpField,
        fieldKey: 'newfieldname',
        data: { ['type']: 'string', ['displayName']: 'newFieldName' },
      } satisfies UpdateMetadataTemplateRequestBody,
    ],
  );
  ```

  ```python Python v10 theme={null}
  client.metadata_templates.update_metadata_template(
      UpdateMetadataTemplateScope.ENTERPRISE,
      template_key,
      [
          UpdateMetadataTemplateRequestBody(
              op=UpdateMetadataTemplateRequestBodyOpField.ADDFIELD,
              field_key="newfieldname",
              data={"type": "string", "displayName": "newFieldName"},
          )
      ],
  )
  ```

  ```csharp .NET v10 theme={null}
  await client.MetadataTemplates.UpdateMetadataTemplateAsync(scope: UpdateMetadataTemplateScope.Enterprise, templateKey: templateKey, requestBody: Array.AsReadOnly(new [] {new UpdateMetadataTemplateRequestBody(op: UpdateMetadataTemplateRequestBodyOpField.AddField) { FieldKey = "newfieldname", Data = new Dictionary<string, object>() { { "type", "string" }, { "displayName", "newFieldName" } } }}));
  ```

  ```swift Swift v10 theme={null}
  try await client.metadataTemplates.updateMetadataTemplate(scope: UpdateMetadataTemplateScope.enterprise, templateKey: templateKey, requestBody: [UpdateMetadataTemplateRequestBody(op: UpdateMetadataTemplateRequestBodyOpField.addField, fieldKey: "newfieldname", data: ["type": "string", "displayName": "newFieldName"])])
  ```

  ```java Java v10 theme={null}
  client.getMetadataTemplates().updateMetadataTemplate(UpdateMetadataTemplateScope.ENTERPRISE, templateKey, Arrays.asList(new UpdateMetadataTemplateRequestBody.Builder(UpdateMetadataTemplateRequestBodyOpField.ADDFIELD).data(mapOf(entryOf("type", "string"), entryOf("displayName", "newFieldName"))).fieldKey("newfieldname").build()))
  ```

  ```java Java v5 theme={null}
  List<MetadataTemplate.FieldOperation> updates = new ArrayList<MetadataTemplate.FieldOperation>();

  String addCategoryFieldJSON = "{\"op\":\"addField\","\"data\":{"
      + "\"displayName\":\"Category\",\"key\":\"category\",\"hidden\":false,\"type\":\"string\"}}";
  updates.add(new MetadataTemplate.FieldOperation(addCategoryFieldJSON));

  String changeTemplateNameJSON = "{\"op\":\"editTemplate\",\"data\":{"
      + "\"displayName\":\"My Metadata\"}}";
  updates.add(new MetadataTemplate.FieldOperation(changeTemplateNameJSON));

  MetadataTemplate.updateMetadataTemplate(api, "enterprise", "myData", updates);
  ```

  ```py Python v4 theme={null}
  template = client.metadata_template('enterprise', 'employeeRecord')
  updates = template.start_update()
  updates.add_enum_option('state', 'WI')
  updates.edit_template({'hidden': False})
  updates.edit_template({'copyInstanceOnItemCopy': False})
  updated_template = template.update_info(updates=updates)
  ```

  ```csharp .NET v6 theme={null}
  var updates = new List<BoxMetadataTemplateUpdate>()
  {
      new BoxMetadataTemplateUpdate()
      {
          Op = MetadataTemplateUpdateOp.addEnumOption,
          FieldKey = "fy",
          Data = new {
              key = "FY20"
          }
      },
      new BoxMetadataTemplateUpdate()
      {
          Op = MetadataTemplateUpdateOp.editTemplate,
          Data = new {
              hidden = false
          }
      }
  };
  BoxMetadataTemplate updatedTemplate = await client.MetadataManager
      .UpdateMetadataTemplate(updates, "enterprise", "marketingCollateral");
  ```

  ```js Node v4 theme={null}
  // Add a new option to the Fiscal Year field, and un-hide the template
  var operations = [
   {
    op: 'addEnumOption',
    fieldKey: 'fy',
    data: { key: 'FY20' }
   },
   {
    op: 'editTemplate',
    data: { hidden: false }
   }
  ];
  client.metadata.updateTemplate('enterprise', 'vcontract', operations)
   .then(template => {
    /* template -> {
     templateKey: 'vcontract',
     scope: 'enterprise_12345',
     displayName: 'Vendor Contract',
     hidden: false,
     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' },
       { key: 'FY20' } ],
      hidden: false } ] }
    */
   });
  ```
</CodeGroup>

<Warning>
  **Admin permissions required**

  Updating metadata templates is restricted to users with admin permission. This
  means that only admins, or co-admins who have been granted rights to **Create
  and edit metadata templates for your company** by the admin can use the web
  app or the API to manage templates.
</Warning>

## Operations

Updates to metadata templates are performed through **operations** rather than
directly changing the template itself. This method allows us to update any
existing metadata instances that are already applied to files and folders.

## Template operations

Template operations update a template's details or fields. These operations are
generally safe as they are applied to any template instance without much impact.

### Edit a template

The operation `editTemplate` allows for editing any of the base properties of
the template, like the `displayName`, `copyInstanceOnItemCopy` and more.

| Parameter |                                                 |
| --------- | ----------------------------------------------- |
| `data`    | An object representing the properties to change |

```json  theme={null}
[
  {
    "op": "editTemplate",
    "data": {
      "displayName": "Client",
      "copyInstanceOnItemCopy": true
    }
  }
]
```

This will update the template to have a new display name of Client.

<Warning>
  This will affect existing instances of this template.
</Warning>

### Add a field to a template

The operation `addField` adds a field to a template.

| Parameter |                                     |
| --------- | ----------------------------------- |
| `data`    | An object representing field to add |

```json  theme={null}
[
  {
    "op": "addField",
    "data": {
      "displayName": "Category",
      "key": "category",
      "hidden": false,
      "type": "string"
    }
  }
]
```

This will add a new non-hidden string field with a `displayName` and `key` of
**category**.

<Warning>
  This will affect existing instances of this template.
</Warning>

### Reorder fields

The operation `reorderFields` reorders the list of fields in a template to match
the requested field list.

| Parameter   |                                                   |
| ----------- | ------------------------------------------------- |
| `fieldKeys` | The new list of field keys in the requested order |

```json  theme={null}
{
  "op": "reorderFields",
  "fieldKeys": ["field2", "field1", "field3"]
}
```

This will reorder the fields for the template to have `field2` first, followed
by `field1`, then `field3`.

<Warning>
  This will affect existing instances of this template. It will reorder the
  fields, yet keep the values of the fields intact.
</Warning>

## Field operations

Field operations transform the schema of a template. The following is a list of
operations that can be used in this API and can potentially change the data of
any previously assigned templates.

These changes will be logged as template changes but not as file changes.

### Edit a field

The operation `editField` edits any number of the base properties of a
field like the `displayName`, `description`, `key`, and `hidden` state.

| Parameter  |                                                                |
| ---------- | -------------------------------------------------------------- |
| `data`     | An object representing the new properties to set for the field |
| `fieldKey` | The key of the field to be edited                              |

```json  theme={null}
{
  "op": "editField",
  "fieldKey": "category",
  "data": {
    "displayName": "Customer Group"
  }
}
```

This will update the field `category` to have a new display name of
**Customer Group**. If the key is changed, existing values of the specified
field are migrated to the new key. The search index will be updated, yet it may
take time depending on how many files are affected by the change.

<Warning>
  This may affect existing instances of this template.
</Warning>

### Remove a field

The operation `removeField` removes a field from a template.

| Parameter  |                                                  |
| ---------- | ------------------------------------------------ |
| `fieldKey` | The key of the field to remove from the template |

```json  theme={null}
{
  "op": "removeField",
  "fieldKey": "brand"
}
```

This will remove the field `brand` from the template as well as all instances of
the template. The search index will be updated, yet it may take time depending on
how many files are affected by the change.

<Warning>
  This will affect existing instances of this template.
</Warning>

## Field Option Operations

Both the <Link href="/guides/metadata/fields/enum">`enum`</Link> and
<Link href="/guides/metadata/fields/multi-select">`multiSelect`</Link> metadata field types support
some additional operations to change the options of the fields.

| Operation                                                                                            |                                                |
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
| <Link href="/guides/metadata/fields/enum#add-an-option">`addEnumOption`</Link>                       | Adds an option to an `enum` field              |
| <Link href="/guides/metadata/fields/enum#edit-an-option">`editEnumOption`</Link>                     | Edits an `enum` field option                   |
| <Link href="/guides/metadata/fields/enum#reorder-options">`reorderEnumOptions`</Link>                | Re-orders the options on an `enum` field       |
| <Link href="/guides/metadata/fields/enum#remove-an-option">`removeEnumOption`</Link>                 | Removes an `enum` field option                 |
| <Link href="/guides/metadata/fields/multi-select#add-an-option">`addMultiSelectOption`</Link>        | Adds an option to a `multiSelect` field        |
| <Link href="/guides/metadata/fields/multi-select#edit-an-option">`editMultiSelectOption`</Link>      | Edits a `multiSelect` field option             |
| <Link href="/guides/metadata/fields/multi-select#reorder-options">`reorderMultiSelectOptions`</Link> | Re-orders the options on a `multiSelect` field |
| <Link href="/guides/metadata/fields/multi-select#remove-an-option">`removeMultiSelectOption`</Link>  | Removes a `multiSelect` field option           |

<RelatedLinks
  title="RELATED APIS"
  items={[
  { label: "Update metadata template", href: "/reference/put-metadata-templates-id-id-schema", badge: "PUT" }
]}
/>

<RelatedLinks
  title="RELATED GUIDES"
  items={[
  { label: "Create a metadata template", href: "/guides/metadata/templates/create", badge: "GUIDE" }
]}
/>
