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

# Manage Departments

> Create, update, and delete departments

## List Departments

<Note>Requires **Admin** or **Owner** role.</Note>

```bash theme={null}
GET /backend/departments
```

**Response (200):**

```json theme={null}
{
  "data": [
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "tenant_id": "d6b10acc-2307-413f-a4de-4c2edf3f9a70",
      "name": "Sales",
      "description": "Sales team",
      "member_count": 5,
      "created_at": "2024-01-15T10:00:00Z",
      "updated_at": "2024-01-15T10:00:00Z"
    }
  ]
}
```

## My Departments

<Note>Accessible by **Operators**. Returns only departments the user belongs to.</Note>

```bash theme={null}
GET /backend/departments/my
```

## Create Department

```bash theme={null}
POST /backend/departments
```

**Body:**

```json theme={null}
{
  "name": "Support",
  "description": "Customer support team"
}
```

| Field         | Type   | Required | Description                                        |
| ------------- | ------ | -------- | -------------------------------------------------- |
| `name`        | string | Yes      | Department name (max 100 chars, unique per tenant) |
| `description` | string | No       | Department description                             |

**Response (201):**

```json theme={null}
{
  "id": "uuid",
  "tenant_id": "uuid",
  "name": "Support",
  "description": "Customer support team",
  "member_count": 0,
  "created_at": "2024-01-15T10:00:00Z",
  "updated_at": "2024-01-15T10:00:00Z"
}
```

## Update Department

```bash theme={null}
PUT /backend/departments/{id}
```

**Body:**

```json theme={null}
{
  "name": "Premium Support",
  "description": "Priority support team"
}
```

All fields are optional. Returns **409 Conflict** if the new name already exists.

## Delete Department

```bash theme={null}
DELETE /backend/departments/{id}
```

**Response:** 204 No Content

<Warning>
  Deleting a department automatically clears all references in lead-channels and channels (set to NULL).
</Warning>
