## Rename file

`PATCH /v1/files/:id`

Renames a file on Bitrix24 Drive. The file location and its other fields do not change.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|---------|
| `id` (path) | number | yes | File ID. List: [`GET /v1/files`](/docs/entities/files/list) with the required `folderId` |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|---------|
| `name` | string | yes | New file name with extension. The name must be available in the destination folder |

## Examples

### curl — personal key

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/files/9251" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "doc-renamed.txt"
  }'
```

### curl — OAuth application

```bash
curl -X PATCH "https://vibecode.bitrix24.com/v1/files/9251" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "doc-renamed.txt"
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/files/9251', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'doc-renamed.txt',
  }),
})

const { success, data } = await res.json()
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/files/9251', {
  method: 'PATCH',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    name: 'doc-renamed.txt',
  }),
})

const { success, data } = await res.json()
```

## Response fields

The field set matches the `GET /v1/files/:id` response.

| Field | Type | Description |
|------|-----|---------|
| `success` | boolean | Always `true` on success |
| `data.id` | number | File identifier |
| `data.name` | string | New file name |
| `data.code` | string\|null | Symbolic file code |
| `data.storageId` | number | Storage ID |
| `data.type` | string | Object type — always `"file"` |
| `data.folderId` | number | Parent folder ID |
| `data.deletedType` | number | Deletion status: `0` — active |
| `data.globalContentVersion` | number | File version counter |
| `data.fileId` | number | Internal file ID in Bitrix24 |
| `data.size` | number | File size in bytes |
| `data.createdBy` | number | Creator user ID |
| `data.updatedBy` | number | ID of the user who performed the rename |
| `data.deletedBy` | number\|null | ID of the user who deleted the file. `null` — not deleted |
| `data.createdAt` | string | Creation date and time (ISO 8601) |
| `data.updatedAt` | string | Rename date and time (ISO 8601) |
| `data.deletedAt` | string\|null | Deletion date. `null` — file not deleted |
| `data.contentProvider` | string | Content provider (may be absent) |
| `data.realObjectId` | number | Internal object ID |
| `data.downloadUrl` | string | Vibecode API address that downloads the file, `GET /v1/files/:id/download`. Send the `X-Api-Key` header when you follow it |
| `data.detailUrl` | string | Link to the file in the Bitrix24 interface |

## Response example

```json
{
  "success": true,
  "data": {
    "id": 9251,
    "name": "doc-renamed.txt",
    "code": null,
    "storageId": 1,
    "type": "file",
    "folderId": 27,
    "deletedType": 0,
    "globalContentVersion": 1,
    "fileId": 34867,
    "size": 11,
    "createdBy": 1,
    "updatedBy": 1,
    "deletedBy": null,
    "createdAt": "2026-05-06T09:32:39.000Z",
    "updatedAt": "2026-05-26T07:08:50.000Z",
    "deletedAt": null,
    "downloadUrl": "https://vibecode.bitrix24.com/v1/files/9251/download",
    "detailUrl": "https://example.bitrix24.com/company/personal/user/1/disk/file/doc-renamed.txt/"
  }
}
```

## Error response example

404 — file not found:

```json
{
  "success": false,
  "error": {
    "code": "ENTITY_NOT_FOUND",
    "message": "diskFile 9251 not found"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 404 | `ENTITY_NOT_FOUND` | A file with the given `id` does not exist |
| 400 | `MISSING_FIELDS` | The request body does not contain the `name` field |
| 400 | `READONLY_FIELD` | The body carries a read-only field, for example `id` or `size` |
| 422 | `BITRIX_ERROR` | The name is already taken in the destination folder. `error.b24Code` is `DISK_OBJ_22000`. Choose another name before retrying |
| 403 | `SCOPE_DENIED` | The key lacks the `disk` scope |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is read-only — see [access rights](/docs/access-rights) |
| 401 | `TOKEN_MISSING` | The key has no configured authorization tokens |
| 401 | `INVALID_API_KEY` | The key is not recognized — no such key exists on the platform |

Full list of common API errors — [Errors](/docs/errors).

## See also

- [Get file](/docs/entities/files/get)
- [File fields](/docs/entities/files/fields)
- [Move file](/docs/entities/files/moveto)
- [Delete file](/docs/entities/files/delete)
- [Files](/docs/entities/files)
