# Create Task

## Task Projects API — Create Task

### Overview

Creates a new task in **Task Projects**.

* **Environment:** `https://sea-staging-h1.ekoapp.com`
* **Base path:** `/api/v1/task-projects`
* **Endpoint:** `POST /api/v1/task-projects/tasks`
* **Auth:** Bearer JWT (see “Authentication”)
* **Content type:** `application/json`
* **Idempotency:** Not specified (assumed non-idempotent)

***

### Authentication

Provide a Bearer token in the `Authorization` header.

```
Authorization: Bearer <JWT>
```

***

### Request

#### Headers

| Header          | Required | Value              |
| --------------- | -------- | ------------------ |
| `Content-Type`  | Yes      | `application/json` |
| `Authorization` | Yes      | `Bearer <JWT>`     |

#### Body (JSON)

| Field                     | Type              | Required | Description                                                                                 |
| ------------------------- | ----------------- | -------- | ------------------------------------------------------------------------------------------- |
| `taskTitle`               | string            | Yes      | Human-readable title of the task.                                                           |
| `taskDescription`         | string            | No       | Details/notes for the task.                                                                 |
| `priority`                | integer           | No       | Priority level. Common patterns are `1`=High, `2`=Medium, `3`=Low (exact mapping may vary). |
| `dueDate`                 | string (ISO 8601) | No       | Due date/time in UTC, e.g. `2025-12-31T23:59:59Z`.                                          |
| `assigneeId`              | string            | No       | User ID to assign the task to.                                                              |
| `checklist`               | array of objects  | No       | Sub-tasks/checklist items.                                                                  |
| `checklist[].description` | string            | Yes\*    | Text for the checklist item.                                                                |
| `checklist[].isDone`      | boolean           | Yes\*    | Completion status for the checklist item.                                                   |
| `parentId`                | string            | No       | ID of the parent container (topic or parent task). Creates a subtask if set.                |

\* Required only if `checklist` is provided.

**Example request body**

```json
{
  "taskTitle": "ประกาศอัปเดตสถานการณ์รายสัปดาห์บนบอร์ดข่าวพนักงาน",
  "taskDescription": "ประกาศอัปเดตสถานการณ์รายสัปดาห์บนบอร์ดข่าวพนักงาน แสดงแนวโน้ม CSAT เทียบกับเป้าหมาย 87 เปอร์เซ็นต์ พร้อมเชิดชูพนักงานแคชเชียร์ที่ได้รับคะแนน 5 ดาวสูงสุด",
  "parentId": "6894448bf0c2250435de2e3c",
  "priority": 2,
  "assigneeId": "677e46a5e2e09e162843f948"
}
```

***

### Responses

> The exact response schema isn’t shown in your snippet. Below is a **typical** pattern for create endpoints—treat this as illustrative unless you have the server contract.

#### 201 Created

```json
{
  "id": "tsk_67a14a2de2e09e162843f955",
  "taskTitle": "ประกาศอัปเดตสถานการณ์รายสัปดาห์บนบอร์ดข่าวพนักงาน",
  "taskDescription": "ประกาศอัปเดตสถานการณ์รายสัปดาห์บนบอร์ดข่าวพนักงาน แสดงแนวโน้ม CSAT เทียบกับเป้าหมาย 87 เปอร์เซ็นต์ พร้อมเชิดชูพนักงานแคชเชียร์ที่ได้รับคะแนน 5 ดาวสูงสุด",
  "parentId": "6894448bf0c2250435de2e3c",
  "priority": 2,
  "assigneeId": "677e46a5e2e09e162843f948",
  "status": "open",
  "createdAt": "2025-08-18T06:20:00Z",
  "updatedAt": "2025-08-18T06:20:00Z"
}
```

#### Error responses (typical)

| Status                     | Meaning                  | Notes                                                  |
| -------------------------- | ------------------------ | ------------------------------------------------------ |
| `400 Bad Request`          | Invalid payload          | Missing required field, wrong types, etc.              |
| `401 Unauthorized`         | Missing/invalid token    | Check `Authorization` header.                          |
| `403 Forbidden`            | Insufficient scope/role  | Token lacks `task-projects:write` scope or equivalent. |
| `404 Not Found`            | Related resource missing | e.g., `assigneeId` not found.                          |
| `409 Conflict`             | Business rule conflict   | Duplicate, invalid state, etc.                         |
| `422 Unprocessable Entity` | Validation failed        | Field-level validation errors.                         |
| `429 Too Many Requests`    | Rate limit               | Retry after `Retry-After`.                             |
| `500/502/503`              | Server errors            | Transient; retry with backoff.                         |

**Example validation error (422)**

```json
{
  "error": "ValidationError",
  "message": "Invalid field(s)",
  "details": [
    { "path": "taskTitle", "message": "taskTitle is required" }
  ]
}
```

***

### cURL example

```bash
curl --location 'https://sea-staging-h1.ekoapp.com/api/v1/task-projects/tasks' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer <REDACTED_JWT>' \
  --data '{
    "taskTitle": "ประกาศอัปเดตสถานการณ์รายสัปดาห์บนบอร์ดข่าวพนักงาน",
    "taskDescription": "ประกาศอัปเดตสถานการณ์รายสัปดาห์บนบอร์ดข่าวพนักงาน แสดงแนวโน้ม CSAT เทียบกับเป้าหมาย 87 เปอร์เซ็นต์ พร้อมเชิดชูพนักงานแคชเชียร์ที่ได้รับคะแนน 5 ดาวสูงสุด",
    "parentId": "6894448bf0c2250435de2e3c",
    "priority": 2,
    "assigneeId": "677e46a5e2e09e162843f948"
  }'
```

***

### Validation & Constraints (recommended)

| Title       | none | Yes | (max 200 characters)                                                                                 |
| ----------- | ---- | --- | ---------------------------------------------------------------------------------------------------- |
| Description | none | No  | (max 5,000 characters)                                                                               |
| Tags        | none | No  | (max 20 tags)                                                                                        |
| Tasks       | none | No  |                                                                                                      |
| Images      | none | No  | <p>Max 12 Images and Attachments</p><p>FE filter</p><ul><li>Images 6</li><li>Attachement 6</li></ul> |

***
