Add users to a department
User Management
Add Users to Department
Admin-only endpoint to add multiple users to a department with a specific role.
PUT
Add users to a department
Admin-only endpoint to add multiple users to a department with a specific role.
Request
Headers
| Name | Type | Required | Description |
|---|---|---|---|
| Authorization | string | Yes | Bearer token |
| Content-Type | string | Yes | application/json |
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| departmentId | string | Yes | Department ID to add users to |
Request Body
Request Body Schema
| Field | Type | Required | Description |
|---|---|---|---|
| userIds | array | Yes | List of user IDs to add to department |
| role | string | Yes | Role to assign to users in department |
Field Details
- userIds: Array of valid MongoDB ObjectIds
- role: Department role (e.g., “manager”, “supervisor”, “agent”, “admin”)
Response
200 OK - Successfully added users to department
400 Bad Request
401 Unauthorized
500 Internal Server Error
Example
Notes
- This is an admin-only endpoint - requires administrative privileges
- Department ID must be a valid MongoDB ObjectId
- All user IDs must be valid MongoDB ObjectIds
- Users can only be added to one department at a time
- If users are already in a department, they will be moved
- The role applies to all users being added
- Users receive department-based permissions based on their role
Role Definitions
| Role | Description | Permissions |
|---|---|---|
| manager | Department manager | Full department access |
| supervisor | Team supervisor | Team management access |
| agent | Regular department member | Standard department access |
| admin | Department administrator | Administrative access |
Use Cases
- Onboarding: Add new employees to their department
- Team Transfers: Move users between departments
- Bulk Assignment: Add multiple users efficiently
- Role Changes: Assign specific roles to new members
Best Practices
- Verify Users: Ensure all user IDs exist before adding
- Role Assignment: Choose appropriate roles for users
- Communication: Notify users of department changes
- Permissions: Review role permissions before assignment
- Audit: Track department membership changes
Error Handling
- Invalid User IDs: Users that don’t exist are skipped
- Already Assigned: Users are moved from current department
- Invalid Role: Returns validation error
- Department Not Found: Returns 404 error
Impact on Users
- Users gain access to department resources
- Previous department assignments are replaced
- Role-based permissions are applied immediately
- Users may see new teams and projects in their dashboard
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Unique identifier of the department
Body
application/json