Skip to main content
PUT
/
user
/
update-department
Update a user's department
curl --request PUT \
  --url http://localhost:2000/user/update-department \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "payload": {
    "userId": "64b7f1a2e4b0a5d3f9c12345",
    "departmentId": "64b7f2b3e4b0a5d3f9c54321"
  }
}
'
{
  "message": "<string>",
  "data": {}
}
Admin-only endpoint to set a user’s department by department ID.

Request

Headers

NameTypeRequiredDescription
AuthorizationstringYesBearer token
Content-TypestringYesapplication/json

Request Body

{
  "payload": {
    "userId": "64b7f1a2e4b0a5d3f9c12345",
    "departmentId": "64b7f2b3e4b0a5d3f9c54321"
  }
}

Request Body Schema

FieldTypeRequiredDescription
payloadobjectYesUpdate payload
payload.userIdstringYesUser ID to update
payload.departmentIdstringYesNew department ID

Response

200 OK - Successfully updated department

{
  "message": "Department updated successfully",
  "data": {}
}

400 Bad Request

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Invalid request body"
  }
}

401 Unauthorized

{
  "error": {
    "code": "UNAUTHORIZED",
    "message": "Missing or invalid token or insufficient permissions"
  }
}

404 Not Found

{
  "error": {
    "code": "USER_NOT_FOUND",
    "message": "User or department not found"
  }
}

500 Internal Server Error

{
  "error": {
    "code": "SERVER_ERROR",
    "message": "Internal server error"
  }
}

Example

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

Authorizations

Authorization
string
header
required

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

Body

application/json
payload
object

Response

Successfully updated department

message
string
data
object