
## Department fields

`GET /v1/departments/fields`

Returns the directory of department fields with their types and the read-only flag, along with the list of operations available in [`POST /v1/batch`](/docs/batch).

## Examples

### curl — personal key

```bash
curl "https://vibecode.bitrix24.com/v1/departments/fields" \
  -H "X-Api-Key: YOUR_API_KEY"
```

### curl — OAuth application

```bash
curl "https://vibecode.bitrix24.com/v1/departments/fields" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN"
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/departments/fields', {
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
  },
})

const { success, data } = await res.json()
console.log('Fields:', Object.keys(data.fields).length)
console.log('Available batch operations:', data.batch)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/departments/fields', {
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
  },
})

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

## Response fields

| Field | Type | RO | Description |
|------|-----|:--:|---------|
| `id` | number | yes | Department identifier |
| `name` | string | | Department name |
| `parentId` | number | | Parent department ID. For a top-level department `1` is used (the virtual root of the tree). Source: [`GET /v1/departments`](./list.md) |
| `headId` | number | | Department head ID. Source: [`GET /v1/users`](/docs/entities/users) |
| `sort` | number | | Sort order of the department among its siblings (integer, ascending) |

## Response example

```json
{
  "success": true,
  "data": {
    "fields": {
      "id": { "type": "number", "readonly": true, "label": "ID", "description": "Unique department identifier." },
      "name": { "type": "string", "readonly": false, "label": "Name", "description": "Department name shown in the company structure." },
      "parentId": { "type": "number", "readonly": false, "label": "Parent department", "description": "ID of the parent department in the hierarchy. For a top-level department 1 is used — the virtual root of the tree." },
      "headId": { "type": "number", "readonly": false, "label": "Head", "description": "ID of the user assigned as the department head." },
      "sort": { "type": "number", "readonly": false, "label": "Sort", "description": "Order of the department among its siblings. Defaults to 500." }
    },
    "batch": ["create", "update", "delete"]
  }
}
```

## Error response example

403 — no scope:

```json
{
  "success": false,
  "error": {
    "code": "SCOPE_DENIED",
    "message": "This endpoint requires 'department' scope"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|---------|
| 403 | `SCOPE_DENIED` | The API key does not have the `department` scope |
| 401 | `TOKEN_MISSING` | The API key has no configured tokens |

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

## See also

- [Create a department](/docs/entities/departments/create) — which fields to pass
- [Update a department](/docs/entities/departments/update) — which fields can be changed
- [List departments](/docs/entities/departments/list) — filtering by these fields
- [Batch](/docs/batch) — bulk operations `create`, `update`, `delete`
- [Entity API](/docs/entity-api) — select to fetch only the needed fields
