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

# Update File Attributes

> Update or add metadata attributes on an existing document in Chamelio's Core. Attributes allow you to attach structured metadata to documents for better organization and searchability.

## Endpoint

```
PATCH /core/files/{file_id}/attributes
```

## Authentication

This endpoint requires authentication via API key. Include your API key in the `X-API-Key` header:

```bash theme={null}
X-API-Key: ca_your_api_key_here
```

## Path Parameters

| Parameter | Type   | Description                                                           |
| --------- | ------ | --------------------------------------------------------------------- |
| `file_id` | string | Unique identifier of the document whose attributes you want to update |

## Request Body

The request body must be a JSON object with the following fields:

### Required Fields

| Field        | Type  | Description                                                                                                                                    |
| ------------ | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `attributes` | array | List of metadata attributes to set on the document. Existing attributes with the same `name` will be overwritten; new attributes will be added |

### Attribute Object

Each object in the `attributes` array contains:

| Field       | Type   | Description                                                                    |
| ----------- | ------ | ------------------------------------------------------------------------------ |
| `name`      | string | Name of the metadata field (e.g., "contract\_type", "effective\_date")         |
| `data_type` | string | Type of the field. Allowed values: `text`, `date`, `number`, `boolean`, `link` |
| `value`     | string | Value of the metadata field (formatted as a string regardless of data\_type)   |

## Request Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X PATCH https://platform.chamelio.ai/core/files/file_abc123/attributes \
    -H "X-API-Key: ca_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "attributes": [
        {
          "name": "contract_type",
          "data_type": "text",
          "value": "Non-Disclosure Agreement"
        },
        {
          "name": "effective_date",
          "data_type": "date",
          "value": "2025-06-01"
        },
        {
          "name": "contract_value",
          "data_type": "number",
          "value": "50000"
        },
        {
          "name": "auto_renew",
          "data_type": "boolean",
          "value": "false"
        }
      ]
    }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://platform.chamelio.ai/core/files/file_abc123/attributes"
  headers = {
      "X-API-Key": "ca_your_api_key_here",
      "Content-Type": "application/json"
  }

  payload = {
      "attributes": [
          {
              "name": "contract_type",
              "data_type": "text",
              "value": "Non-Disclosure Agreement"
          },
          {
              "name": "effective_date",
              "data_type": "date",
              "value": "2025-06-01"
          },
          {
              "name": "contract_value",
              "data_type": "number",
              "value": "50000"
          }
      ]
  }

  response = requests.patch(url, json=payload, headers=headers)
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://platform.chamelio.ai/core/files/file_abc123/attributes', {
    method: 'PATCH',
    headers: {
      'X-API-Key': 'ca_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      attributes: [
        {
          name: 'contract_type',
          data_type: 'text',
          value: 'Non-Disclosure Agreement'
        },
        {
          name: 'effective_date',
          data_type: 'date',
          value: '2025-06-01'
        },
        {
          name: 'contract_value',
          data_type: 'number',
          value: '50000'
        }
      ]
    })
  });

  const data = await response.json();
  console.log(data);
  ```
</CodeGroup>

## Response

### Success Response

**Status Code:** `200 OK`

```json theme={null}
{
  "file_id": "file_abc123",
  "status": "success",
  "updated_attributes": [
    "contract_type",
    "effective_date",
    "contract_value",
    "auto_renew"
  ]
}
```

### Response Fields

| Field                | Type   | Description                                             |
| -------------------- | ------ | ------------------------------------------------------- |
| `file_id`            | string | Unique identifier of the updated document               |
| `status`             | string | Update status (always "success" for successful updates) |
| `updated_attributes` | array  | List of attribute names that were created or updated    |

## Error Responses

### 401 Unauthorized

Returned when authentication fails. See the [authentication errors](/api-reference/introduction#authentication-errors) section for details.

```json theme={null}
{
  "detail": "Invalid API key"
}
```

### 404 Not Found

Returned when the specified file does not exist or is not accessible with your API key.

```json theme={null}
{
  "detail": "File not found"
}
```

### 422 Validation Error

Returned when the request body is invalid or contains unsupported attribute types.

```json theme={null}
{
  "detail": [
    {
      "loc": ["body", "attributes", 0, "data_type"],
      "msg": "value is not a valid enum member; permitted: 'text', 'date', 'number', 'boolean', 'link'",
      "type": "type_error.enum"
    }
  ]
}
```

### 500 Internal Server Error

Returned when the attribute update fails due to a server error.

```json theme={null}
{
  "detail": "Failed to update attributes: Internal processing error"
}
```

## Notes

<Info>
  This endpoint uses a **merge strategy**: attributes you provide are added or overwritten, while attributes not included in the request are left unchanged. To remove an attribute entirely, contact support.
</Info>

<Tip>
  Use the same `data_type` values consistently for a given attribute name across documents. Mixing types for the same field name may cause unexpected behavior in filters and reports.
</Tip>

## Use Cases

This endpoint is useful for:

* **Post-upload enrichment** - Add or correct metadata after a document has been processed
* **Bulk attribute updates** - Programmatically update attributes across many documents via automation
* **Workflow integration** - Update document metadata as part of a downstream workflow (e.g., after review or signing)
* **Data correction** - Fix incorrect attribute values without re-uploading the document
