Retrieve users filtered by their assigned role. Useful for getting lists of students, lecturers, or administrators. Requires Admin or Lecturer privileges.
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
}