GET /api/v1/users/by-role

Retrieve users filtered by their assigned role. Useful for getting lists of students, lecturers, or administrators. Requires Admin or Lecturer privileges.

Query parameters

  • role string

    Filter users by their assigned role in the system

    Values are STUDENT, LECTURER, or ADMIN.

Responses

  • 200 application/json

    Users filtered by role retrieved successfully

  • 400 application/json

    Invalid role parameter provided

  • 401 application/json

    Authentication token required

  • 403 application/json

    Admin or Lecturer privileges required

GET /api/v1/users/by-role
curl \
 --request GET 'http://localhost:3500/api/v1/users/by-role'
Response examples (200)
[
  {
    "id": "user-uuid-1",
    "role": "STUDENT",
    "email": "alice.johnson@student.edu",
    "phone": "+254712345681",
    "status": "ACTIVE",
    "student": {
      "cohortId": "cohort-2024-uuid",
      "departmentId": "cs-department-uuid",
      "Registration_number": "CS/2024/001"
    },
    "lastname": "Johnson",
    "firstname": "Alice",
    "instituteid": "institute-uuid-here"
  },
  {
    "id": "user-uuid-2",
    "role": "STUDENT",
    "email": "bob.smith@student.edu",
    "phone": "+254712345682",
    "status": "ACTIVE",
    "student": {
      "cohortId": "cohort-2024-uuid",
      "departmentId": "cs-department-uuid",
      "Registration_number": "CS/2024/002"
    },
    "lastname": "Smith",
    "firstname": "Bob",
    "instituteid": "institute-uuid-here"
  }
]
Response examples (400)
{
  "error": "Bad Request",
  "message": [
    "role must be one of: STUDENT, LECTURER, ADMIN"
  ],
  "statusCode": 400
}
Response examples (401)
{
  "error": "Unauthorized",
  "message": "Unauthorized",
  "statusCode": 401
}
Response examples (403)
{
  "error": "Forbidden",
  "message": "Insufficient permissions. Admin or Lecturer role required.",
  "statusCode": 403
}