> ## 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 Users

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


Admin-only endpoint to retrieve a list of users 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 users) |

### Query Parameters

| Parameter        | Type   | Required | Description                      |
| ---------------- | ------ | -------- | -------------------------------- |
| departmentFilter | string | No       | Department ID to filter users by |

#### departmentFilter Details

* Must be a valid MongoDB ObjectId of a department
* Can be `null` to return all users that are not part of any department
* Example: `"64ef3c29f9a1c27e1b2c3a4d"`

## Response

### 200 OK - Successfully retrieved user list

```json theme={null}
{
  "message": "Users retrieved successfully",
  "data": {
    "total": 25,
    "users": [
      {
        "_id": "64b7f1a2e4b0a5d3f9c12345",
        "emails": "user@example.com",
        "firstName": "John",
        "lastName": "Doe",
        "role": "user",
        "department": {
          "_id": "64b7f2b3e4b0a5d3f9c54321",
          "name": "Customer Support"
        },
        "rcExtension": "1234",
        "phone": "+1-555-555-5555"
      }
    ]
  }
}
```

### 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 users

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

### Get all users

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

### Get users from specific department

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

### Get users without department

```bash theme={null}
curl -X GET 'http://localhost:2000/user/list/0/10?departmentFilter=null' \
  -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 users
* The response includes a total count for pagination controls
* Users are returned with summary information, not full profile data
* Use departmentFilter to narrow down results by department


## OpenAPI

````yaml GET /user/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:
  /user/list/{start}/{end}:
    get:
      tags:
        - Users
      summary: Get list of users with pagination
      description: >
        Admin-only endpoint to retrieve a list of users.   - If both `start` and
        `end` are `0`, all users are returned.   - Otherwise, returns users
        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 users)
          example: 10
        - name: departmentFilter
          in: query
          required: false
          schema:
            type: string
            nullable: true
          description: >
            Department ID to filter users by.   - Must be a valid MongoDB
            ObjectId of a department.   - Can be `null` to return all users that
            is not a part of any department.
          example: 64ef3c29f9a1c27e1b2c3a4d
      responses:
        '200':
          description: Successfully retrieved user list
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  data:
                    type: object
                    properties:
                      total:
                        type: integer
                        description: Total number of users
                        example: 25
                      users:
                        type: array
                        items:
                          $ref: '#/components/schemas/UserSummary'
        '401':
          description: Unauthorized (missing/invalid token or insufficient permissions)
        '500':
          description: Server error
      security:
        - bearerAuth: []
components:
  schemas:
    UserSummary:
      type: object
      properties:
        emails:
          type: array
          items:
            type: string
          example:
            - user@example.com
        personalInformation:
          type: object
          example:
            firstName: John
            lastName: Doe
        role:
          type: string
          example: employee
        department:
          type: object
          example:
            id: 64ef3c29f9a1c27e1b2c3a4d
            role: manager
        reportsTo:
          type: string
          example: 64ef3c29f9a1c27e1b2c3a99
        createdAt:
          type: string
          format: date-time
          example: '2025-09-12T08:30:00Z'
        config:
          type: object
          properties:
            lastActive:
              type: string
              format: date-time
              example: '2025-09-12T09:15:00Z'
        linkedAccounts:
          type: object
          description: Object of linked accounts meta data.
          example:
            google:
              meta:
                email: zain
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````