# 16. API get task

## API: GET /tasks

API dùng để **lấy danh sách Task** với đầy đủ filter theo ngày tạo, ngày hết hạn, trạng thái, độ ưu tiên và người được giao.

### Endpoint

GET <https://apiring.antbuddy.com/tasks>

### Headers

| Name         | Required | Description                         |
| ------------ | -------- | ----------------------------------- |
| Content-Type | Yes      | application/json                    |
| apikey       | Yes      | Valid API key assigned to the user. |

### Query Parameters

| Param         | Type            | Example                             | Mô tả                                                                                   |
| ------------- | --------------- | ----------------------------------- | --------------------------------------------------------------------------------------- |
| fromCreatedAt | ISO date string | 2024-01-01                          | Lấy task có createdAt >= từ ngày.                                                       |
| toCreatedAt   | ISO date string | 2024-01-31                          | Lấy task có createdAt <= đến ngày.                                                      |
| fromDueAt     | ISO date string | 2024-02-01                          | Lấy task có dueAt >= từ ngày.                                                           |
| toDueAt       | ISO date string | 2024-02-10                          | Lấy task có dueAt <= đến ngày.                                                          |
| status        | String          | TO\_DO,DOING,DONE,DEFERRED          | Lọc theo trạng thái. Có thể truyền nhiều trạng thái, cách nhau bằng dấu phẩy.           |
| priority      | String          | LOW,NORMAL,HIGH                     | Lọc theo độ ưu tiên. Có thể truyền nhiều độ ưu tiên, cách nhau bằng dấu phẩy.           |
| assignTo      | String          | <user1@gmail.com>,<user2@gmail.com> | Lọc theo email của người được giao. Có thể truyền nhiều email, cách nhau bằng dấu phẩy. |
| page          | Number          | 2                                   | Chỉ định trang (dùng cho phân trang). Mặc định là 1.                                    |
| limit         | Number          | 50                                  | Số lượng task trên mỗi trang. Mặc định là 20, tối đa là 100.                            |

### Request Example

```
# Lấy các task có độ ưu tiên 'high' hoặc 'normal',
# được giao cho 2 user,
# và hết hạn trong tháng 2/2024
# Lấy trang 1, 10 item
```

```
curl 
--request GET \
--location 'https://apiring.antbuddy.com/tasks?priority=HIGH,NORMAL&assignTo=user1@gmail.com,user2@gmail.com&fromDueAt=2024-02-01&toDueAt=2024-02-29&page=1&limit=10' \
--header 'Content-Type: application/json' \
--header 'apikey: YOUR_API_KEY'
```

### Response Example

```
{
  "success": true,
  "data": [
    {
      "_id": "664f1825e3984a1b154382b2",
      "dueAt": 1716545957174,
      "isCompleted": false,
      "completionTime": 0,
      "priority": "NORMAL",
      "status": "TO_DO",
      "assignTo": {
        "_id": "65211474393a22650d6cb996",
        "firstname": "Dai",
        "lastname": "Toan",
        "email": "ngochungle1331@gmail.com"
      },
      "category": null,
      "contact": null,
      "group": "652115d4393a22650d6cbb42",
      "createdBy": {
        "_id": "65211474393a22650d6cb996",
        "firstname": "Dai",
        "lastname": "Toan",
        "email": "ngochungle1331@gmail.com"
      },
      "org": "65211476393a22650d6cb999",
      "assignedAt": 1716459557420,
      "createdAt": 1716459557448,
      "updatedAt": 1716459557454,
      "taskId": 1
    }
  ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.antbuddy.com/huong-dan-tich-hop-api-team-technical-api-integration-guide-technical-team/antcrm/16.-api-get-task.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
