Skip to main content

Tasks API

The Tasks API allows authenticated users to create, assign, update, track, and manage tasks. Tasks can include descriptions, due dates, assigned users, attachments, and progress tracking.

Both Admin and Member roles can interact with tasks, but access levels differ:

RolePermissions
AdminCan view, create, update, and delete any task
MemberCan create tasks and only view or update tasks they created or are assigned to

Base URL

/api/tasks

Endpoints Overview

MethodEndpointDescriptionAuth RequiredRole
POST/Create a new taskYesAdmin / Member
GET/Get tasks visible to the userYesAdmin / Member
GET/:taskIdGet details of a specific taskYesAdmin / Member (if assigned)
PUT/:taskIdUpdate a taskYesAdmin / Member (if creator/assigned)
DELETE/:taskIdDelete a taskYesAdmin only
PATCH/:taskId/progressUpdate task progress (0–100%)YesAdmin / Member (if assigned)
POST/:taskId/checklistAdd a checklist itemYesAdmin / Member (if assigned)
PATCH/:taskId/checklist/:itemIdUpdate a checklist item's completion stateYesAdmin / Member (if assigned)

Task Structure

A task contains the following fields:

{
"title": "Prepare Project Report",
"description": "Compile milestone achievements",
"priority": "High",
"status": "Pending",
"dueDate": "2025-01-20",
"assignedTo": ["<user_id>"],
"attachments": ["https://filelink.com/file.pdf"],
"todoChecklist": [
{ "text": "Gather docs", "completed": false }
],
"progress": 40
}

1. Create a Task

POST /

Creates a new task in the system.

Request Body

{
"title": "Design Homepage UI",
"description": "Initial UI/UX layout",
"priority": "High",
"dueDate": "2025-01-29",
"assignedTo": ["65f93b8c9e9a2d52c3a421de"]
}

Response (201 Created)

{
"message": "Task created successfully",
"task": {
"_id": "65f94a9c19d23e",
"title": "Design Homepage UI",
"priority": "High",
"status": "Pending"
}
}

2. Get Tasks (Filtered by Role)

GET /

Retrieves tasks based on the user's role:

  • Admin → Gets all tasks.
  • Member → Gets only tasks they created or were assigned to.

Response (200 OK)

[
{
"_id": "65f94a9c19d23e",
"title": "Design Homepage UI",
"status": "Pending",
"assignedTo": ["65f93b8c9e9a2d52c3a421de"],
"progress": 40
}
]

3. Get Task by ID

GET /:taskId

Returns detailed information for a single task.

Response (200 OK)

{
"_id": "65f94a9c19d23e",
"title": "Design Homepage UI",
"description": "Initial UI/UX layout",
"assignedTo": ["65f93b8c9e9a2d52c3a421de"],
"todoChecklist": [
{ "text": "Sketch wireframe", "completed": false }
]
}

4. Update Task

PUT /:taskId

Updates task content including title, status, description, and other fields.

Request Body

{
"status": "InProgress",
"description": "Working on visual layout"
}

Response (200 OK)

{
"message": "Task updated successfully",
"task": {
"_id": "65f94a9c19d23e",
"title": "Design Homepage UI",
"status": "InProgress",
"description": "Working on visual layout"
}
}

5. Delete Task (Admin Only)

DELETE /:taskId

Permanently removes a task from the system. Only admins can delete tasks.

Response (200 OK)

{
"message": "Task deleted successfully"
}

6. Update Task Progress

PATCH /:taskId/progress

Updates the progress percentage of a task (0–100%).

Request Body

{
"progress": 75
}

Response (200 OK)

{
"message": "Progress updated",
"progress": 75
}

7. Add Checklist Item

POST /:taskId/checklist

Adds a new item to the task's checklist.

Request Body

{
"text": "Run accessibility audit"
}

Response (201 Created)

{
"message": "Checklist item added successfully",
"checklist": [
{ "_id": "65f95b2d3a1f34", "text": "Run accessibility audit", "completed": false }
]
}

8. Update Checklist Completion

PATCH /:taskId/checklist/:itemId

Updates the completion status of a specific checklist item.

Request Body

{
"completed": true
}

Response (200 OK)

{
"message": "Checklist item updated",
"item": {
"_id": "65f95b2d3a1f34",
"text": "Run accessibility audit",
"completed": true
}
}

Common Error Responses

StatusMeaning
400Invalid input or missing required fields
401Missing or invalid token
403User does not have permission
404Task not found