Skip to main content
GET
/
department
/
list
/
{start}
/
{end}
Get list of departments with pagination
curl --request GET \
  --url http://localhost:2000/department/list/{start}/{end} \
  --header 'Authorization: Bearer <token>'
{
  "message": "<string>",
  "data": {
    "total": 15,
    "departments": [
      {
        "_id": "64ef3c29f9a1c27e1b2c3a4d",
        "name": "Engineering",
        "parentDepartment": {
          "_id": "64ef3c29f9a1c27e1b2c3aaa",
          "name": "Technology",
          "description": "Some description for this department",
          "code": "TECH"
        },
        "manager": {
          "_id": "64ef3c29f9a1c27e1b2c3a4d",
          "emails": [
            "[email protected]"
          ],
          "personalInformation": {
            "firstName": "John",
            "lastName": "Doe",
            "name": "John Doe"
          }
        },
        "description": "Handles all software engineering operations"
      }
    ]
  }
}
Admin-only endpoint to retrieve a list of departments with pagination support.

Request

Headers

NameTypeRequiredDescription
AuthorizationstringYesBearer token

Path Parameters

ParameterTypeRequiredDescription
startintegerYesStarting index (0 for beginning)
endintegerYesEnding index (0 to return all departments)

Response

200 OK - Successfully retrieved department list

{
  "message": "Departments retrieved successfully",
  "data": {
    "total": 15,
    "departments": [
      {
        "_id": "64b7f2b3e4b0a5d3f9c54321",
        "name": "Customer Support",
        "description": "Handles customer inquiries and support tickets",
        "parentId": null,
        "createdAt": "2024-01-15T10:30:00.000Z",
        "updatedAt": "2024-01-15T10:30:00.000Z"
      },
      {
        "_id": "64b7f3c4e4b0a5d3f9c98765",
        "name": "Engineering",
        "description": "Software development and technical operations",
        "parentId": null,
        "createdAt": "2024-01-15T10:30:00.000Z",
        "updatedAt": "2024-01-15T10:30:00.000Z"
      }
    ]
  }
}

401 Unauthorized

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

500 Internal Server Error

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

Examples

Get first 10 departments

curl -X GET 'http://localhost:2000/department/list/0/10' \
  -H 'Authorization: Bearer your-jwt-token'

Get all departments

curl -X GET 'http://localhost:2000/department/list/0/0' \
  -H 'Authorization: Bearer your-jwt-token'

Get departments 11-20

curl -X GET 'http://localhost:2000/department/list/10/20' \
  -H 'Authorization: Bearer your-jwt-token'

Notes

  • This is an admin-only endpoint - requires administrative privileges
  • Pagination is zero-based (start at 0)
  • Setting both start and end to 0 returns all departments
  • The response includes a total count for pagination controls
  • Departments are returned as a flat list without hierarchy
  • Use the /department/hierarchy endpoint for hierarchical view
  • Departments are sorted by creation date (newest first)
  • The list includes both parent and child departments

Authorizations

Authorization
string
header
required

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

Path Parameters

start
integer
required

Starting index (0 for beginning)

Required range: x >= 0
end
integer
required

Ending index (0 to return all departments)

Required range: x >= 0

Response

Successfully retrieved department list

message
string
data
object