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

# Update Department Role

> Admin-only endpoint to update a user's department role by user ID.

Admin-only endpoint to update a user's department role by user ID.

## Request

### Headers

| Name          | Type   | Required | Description      |
| ------------- | ------ | -------- | ---------------- |
| Authorization | string | Yes      | Bearer token     |
| Content-Type  | string | Yes      | application/json |

### Request Body

```json theme={null}
{
  "payload": {
    "userId": "64ef3c29f9a1c27e1b2c3a4d",
    "departmentRole": "manager"
  }
}
```

### Request Body Schema

| Field                  | Type   | Required | Description         |
| ---------------------- | ------ | -------- | ------------------- |
| payload                | object | Yes      | Update payload      |
| payload.userId         | string | Yes      | User ID to update   |
| payload.departmentRole | string | Yes      | New department role |

## Response

### 200 OK - Successfully updated department role

```json theme={null}
{
  "message": "Department role updated successfully",
  "data": {}
}
```

### 400 Bad Request

```json theme={null}
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid request body"
  }
}
```

### 401 Unauthorized

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

### 404 Not Found

```json theme={null}
{
  "error": {
    "code": "USER_NOT_FOUND",
    "message": "User not found"
  }
}
```

### 500 Internal Server Error

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

## Example

```bash theme={null}
curl -X PUT 'http://localhost:2000/update-department-role' \
  -H 'Authorization: Bearer your-jwt-token' \
  -H 'Content-Type: application/json' \
  -d '{
    "payload": {
      "userId": "64ef3c29f9a1c27e1b2c3a4d",
      "departmentRole": "manager"
    }
  }'
```

## Notes

* This is an admin-only endpoint - requires administrative privileges
* The user ID must be a valid MongoDB ObjectId
* Department roles can include: "manager", "supervisor", "agent", "admin", etc.
* The role may affect the user's permissions within their department
* Only administrators can update other users' department roles
* Role names should match predefined roles in your system


## OpenAPI

````yaml PUT /update-department-role
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:
  /update-department-role:
    put:
      tags:
        - Users
      summary: Update a user's department role
      description: Admin-only endpoint to update a user's department role by user ID.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                payload:
                  $ref: '#/components/schemas/UpdateDepartmentRolePayload'
      responses:
        '200':
          description: Successfully updated department role
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  data:
                    type: object
        '400':
          description: Validation error / bad request
        '401':
          description: Unauthorized (missing/invalid token or insufficient permissions)
        '404':
          description: User not found
        '500':
          description: Server error
      security:
        - bearerAuth: []
components:
  schemas:
    UpdateDepartmentRolePayload:
      type: object
      required:
        - userId
        - departmentRole
      properties:
        userId:
          type: string
          description: Unique identifier of the user
          example: 64ef3c29f9a1c27e1b2c3a4d
        departmentRole:
          type: string
          description: The new department role to assign
          example: manager
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````