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

# List Departments

> Admin-only endpoint to retrieve a list of departments.   - If both `start` and `end` are `0`, all departments are returned.   - Otherwise, returns departments between the given start and end indexes (zero-based).


Admin-only endpoint to retrieve a list of departments with pagination support.

## Request

### Headers

| Name          | Type   | Required | Description  |
| ------------- | ------ | -------- | ------------ |
| Authorization | string | Yes      | Bearer token |

### Path Parameters

| Parameter | Type    | Required | Description                                |
| --------- | ------- | -------- | ------------------------------------------ |
| start     | integer | Yes      | Starting index (0 for beginning)           |
| end       | integer | Yes      | Ending index (0 to return all departments) |

## Response

### 200 OK - Successfully retrieved department list

```json theme={null}
{
  "message": "Departments retrieved successfully",
  "data": {
    "total": 15,
    "departments": [
      {
        "_id": "64b7f2b3e4b0a5d3f9c54321",
        "name": "Customer Support",
        "description": "Handles customer inquiries and support tickets",
        "parentId": null,
        "createdAt": "2024-01-15T10:30:00.000Z",
        "updatedAt": "2024-01-15T10:30:00.000Z"
      },
      {
        "_id": "64b7f3c4e4b0a5d3f9c98765",
        "name": "Engineering",
        "description": "Software development and technical operations",
        "parentId": null,
        "createdAt": "2024-01-15T10:30:00.000Z",
        "updatedAt": "2024-01-15T10:30:00.000Z"
      }
    ]
  }
}
```

### 401 Unauthorized

```json theme={null}
{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Missing or invalid token or insufficient permissions"
  }
}
```

### 500 Internal Server Error

```json theme={null}
{
  "error": {
    "code": "SERVER_ERROR",
    "message": "Internal server error"
  }
}
```

## Examples

### Get first 10 departments

```bash theme={null}
curl -X GET 'http://localhost:2000/department/list/0/10' \
  -H 'Authorization: Bearer your-jwt-token'
```

### Get all departments

```bash theme={null}
curl -X GET 'http://localhost:2000/department/list/0/0' \
  -H 'Authorization: Bearer your-jwt-token'
```

### Get departments 11-20

```bash theme={null}
curl -X GET 'http://localhost:2000/department/list/10/20' \
  -H 'Authorization: Bearer your-jwt-token'
```

## Notes

* This is an admin-only endpoint - requires administrative privileges
* Pagination is zero-based (start at 0)
* Setting both start and end to 0 returns all departments
* The response includes a total count for pagination controls
* Departments are returned as a flat list without hierarchy
* Use the `/department/hierarchy` endpoint for hierarchical view
* Departments are sorted by creation date (newest first)
* The list includes both parent and child departments


## OpenAPI

````yaml GET /department/list/{start}/{end}
openapi: 3.0.3
info:
  title: COMPASS API
  version: 1.0.0
  description: OpenAPI specification for the Compass backend routes.
servers:
  - url: http://localhost:2000
    description: Local development server
security: []
tags:
  - name: Auth
    description: >-
      Authentication and session management endpoints (OAuth and session
      validation)
  - name: Users
    description: Operations for managing user records
  - name: Departments
    description: Operations for managing departments
  - name: Email Meter
    description: APIs to get Email Meter Stats
  - name: HubSpot Tickets
    description: Feedback APIs
  - name: Permissions
    description: Permissions APIs
  - name: Transcription
    description: Transcription APIs
paths:
  /department/list/{start}/{end}:
    get:
      tags:
        - Departments
      summary: Get list of departments with pagination
      description: >
        Admin-only endpoint to retrieve a list of departments.   - If both
        `start` and `end` are `0`, all departments are returned.   - Otherwise,
        returns departments between the given start and end indexes
        (zero-based).
      parameters:
        - name: start
          in: path
          required: true
          schema:
            type: integer
            minimum: 0
          description: Starting index (0 for beginning)
          example: 0
        - name: end
          in: path
          required: true
          schema:
            type: integer
            minimum: 0
          description: Ending index (0 to return all departments)
          example: 10
      responses:
        '200':
          description: Successfully retrieved department list
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  data:
                    type: object
                    properties:
                      total:
                        type: integer
                        description: Total number of departments
                        example: 15
                      departments:
                        type: array
                        items:
                          $ref: '#/components/schemas/Department'
        '401':
          description: Unauthorized (missing/invalid token or insufficient permissions)
        '500':
          description: Server error
      security:
        - bearerAuth: []
components:
  schemas:
    Department:
      type: object
      properties:
        _id:
          type: string
          example: 64ef3c29f9a1c27e1b2c3a4d
        name:
          type: string
          example: Engineering
        parentDepartment:
          type: object
          description: Parent department info (if applicable)
          example:
            _id: 64ef3c29f9a1c27e1b2c3aaa
            name: Technology
            description: Some description for this department
            code: TECH
        manager:
          $ref: '#/components/schemas/MatchSuggestionUser'
          type: object
          description: Manager info attached to department
        description:
          type: string
          example: Handles all software engineering operations
    MatchSuggestionUser:
      type: object
      properties:
        _id:
          type: string
          example: 64ef3c29f9a1c27e1b2c3a4d
        emails:
          type: array
          items:
            type: string
          example:
            - user@example.com
        personalInformation:
          type: object
          properties:
            firstName:
              type: string
              example: John
            lastName:
              type: string
              example: Doe
            name:
              type: string
              example: John Doe
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````