Skip to main content
PUT
Add users to a department
Admin-only endpoint to add multiple users to a department with a specific role.

Request

Headers

Path Parameters

Request Body

Request Body Schema

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

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

  1. Verify Users: Ensure all user IDs exist before adding
  2. Role Assignment: Choose appropriate roles for users
  3. Communication: Notify users of department changes
  4. Permissions: Review role permissions before assignment
  5. 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

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

departmentId
string
required

Unique identifier of the department

Body

application/json
users
string[]
required

List of user IDs to add to the department

Example:
departmentRole
string
required

Role to assign to the users in the department

Example:

"Manager"

Response

Successfully added users to department

message
string
Example:

"Successfully added users to Engineering department"

data
object