> ## 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 User Department

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

Admin-only endpoint to set a user's department by department 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": "64b7f1a2e4b0a5d3f9c12345",
    "departmentId": "64b7f2b3e4b0a5d3f9c54321"
  }
}
```

### Request Body Schema

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

## Response

### 200 OK - Successfully updated department

```json theme={null}
{
  "message": "Department 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 or department 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/user/update-department' \
  -H 'Authorization: Bearer your-jwt-token' \
  -H 'Content-Type: application/json' \
  -d '{
    "payload": {
      "userId": "64b7f1a2e4b0a5d3f9c12345",
      "departmentId": "64b7f2b3e4b0a5d3f9c54321"
    }
  }'
```

## Notes

* This is an admin-only endpoint - requires administrative privileges
* Both user ID and department ID must be valid MongoDB ObjectIds
* The department ID must correspond to an existing department
* Users can be moved between departments using this endpoint
* Only administrators can update other users' departments
* This may affect the user's permissions if departments have role-based access


## OpenAPI

````yaml PUT /user/update-department
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/update-department:
    put:
      tags:
        - Users
      summary: Update a user's department
      description: Admin-only endpoint to set a user's department by department ID.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                payload:
                  $ref: '#/components/schemas/UpdateDepartmentPayload'
      responses:
        '200':
          description: Successfully updated department
          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 or department not found
        '500':
          description: Server error
      security:
        - bearerAuth: []
components:
  schemas:
    UpdateDepartmentPayload:
      type: object
      required:
        - userId
        - departmentId
      properties:
        userId:
          type: string
          example: 64b7f1a2e4b0a5d3f9c12345
        departmentId:
          type: string
          example: 64b7f2b3e4b0a5d3f9c54321
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````