> For the complete documentation index, see [llms.txt](https://genfarmer-support.gitbook.io/genfarmer/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://genfarmer-support.gitbook.io/genfarmer/thanh-menu-chinh/api.md).

# API

## Tài liệu API GenFarmer

Chào mừng bạn đến với tài liệu API của GenFarmer. Tài liệu này giúp bạn hiểu và sử dụng các endpoint RESTful để quản lý hệ thống tự động hóa của GenFarmer.

***

### 🧠 Giới thiệu tổng quan

GenFarmer cung cấp các endpoint để quản lý **Ứng dụng tự động hóa (Automation Apps)**, **Nhiệm vụ (Tasks)** và **Lượt chạy (Runs)** có thể gán cho thiết bị thực hiện tự động.

***

### 📦 URL cơ bản

```
http://127.0.0.1:55554/
```

***

### 📁 Nhóm API: Ứng dụng tự động hóa

#### 🔍 Danh sách ứng dụng

* **Phương thức:** `GET`
* **Đường dẫn:** `/automation/apps`

**Ví dụ cURL:**

```bash
curl -X GET 'http://127.0.0.1:55554/automation/apps?userId=3&page=1&limit=25&order=desc&orderBy=updatedAt'
```

***

#### 🔍 Chi tiết ứng dụng

* **Phương thức:** `GET`
* **Đường dẫn:** `/automation/apps/:id`

**Ví dụ cURL:**

```bash
curl -X GET 'http://127.0.0.1:55554/automation/apps/adoFNVNN6Jwl8FlbZCfni'
```

***

#### 🔧 Cập nhật ứng dụng

* **Phương thức:** `PUT`
* **Đường dẫn:** `/automation/apps`

**Ví dụ cURL:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/apps' \
  -H 'Content-Type: application/json' \
  -d '{"id":"adoFNVNN6Jwl8FlbZCfni","userId":3,"name":"New App","description":"","version":"1.0.0","script":{"flow":{"nodes":[],"edges":[]}}}'
```

***

#### ❌ Xoá ứng dụng

* **Phương thức:** `DELETE`
* **Đường dẫn:** `/automation/apps`

**Ví dụ cURL:**

```bash
curl -X DELETE 'http://127.0.0.1:55554/automation/apps' \
  -H 'Content-Type: application/json' \
  -d '{"ids": ["2ykTiCbEOAYC_5_tR5Wp-"]}'
```

***

### 🧾 Nhóm API: Nhiệm vụ (Task)

#### ➕ Tạo nhiệm vụ

* **Phương thức:** `POST`
* **Đường dẫn:** `/automation/tasks`

**Ví dụ cURL:**

```bash
curl -X POST 'http://127.0.0.1:55554/automation/tasks' \
  -H 'Content-Type: application/json' \
  -d '{"appId":"adoFNVNN6Jwl8FlbZCfni","input":[],"userId":3,"name":"test","devices":{"enable":true,"list":[]}}'
```

***

#### 🛠 Cập nhật nhiệm vụ

* **Phương thức:** `PUT`
* **Đường dẫn:** `/automation/tasks/:id`

**Ví dụ cURL:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/tasks/uNDVKT_VwhEDuXT3PGUUv' \
  -H 'Content-Type: application/json' \
  -d '{"id":"uNDVKT_VwhEDuXT3PGUUv","userId":3,"appId":"adoFNVNN6Jwl8FlbZCfni","name":"test","devices":{"enable":true,"list":[{"id":"emulator-5554","serialNo":"00f65a5d","name":"SM-G960N"}]}}'
```

***

#### 🔗 Gán thiết bị vào nhiệm vụ

* **Phương thức:** `PUT`
* **Đường dẫn:** `/automation/tasks/:id/add-devices`

**Ví dụ cURL:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/tasks/uNDVKT_VwhEDuXT3PGUUv/add-devices' \
  -H 'Content-Type: application/json' \
  -d '{"devices":{"enabled":true,"list":[{"id":"emulator-5554","serialNo":"00f65a5d","name":"SM-G960N"}]}}'
```

***

#### 🔗 Gỡ thiết bị khỏi nhiệm vụ

* **Phương thức:** `PUT`
* **Đường dẫn:** `/automation/tasks/:id/remove-devices`

**Ví dụ cURL:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/tasks/uNDVKT_VwhEDuXT3PGUUv/remove-devices' \
  -H 'Content-Type: application/json' \
  -d '{"ids":["emulator-5554"]}'
```

***

#### 🗑 Xoá nhiệm vụ

* **Phương thức:** `DELETE`
* **Đường dẫn:** `/automation/tasks`

**Ví dụ cURL:**

```bash
curl -X DELETE 'http://127.0.0.1:55554/automation/tasks' \
  -H 'Content-Type: application/json' \
  -d '{"ids": ["uNDVKT_VwhEDuXT3PGUUv"]}'
```

***

### 🚀 Nhóm API: Lượt chạy (Run)

#### ▶️ Tạo lượt chạy

* **Phương thức:** `POST`
* **Đường dẫn:** `/automation/runs`

**Ví dụ cURL:**

```bash
curl -X POST 'http://127.0.0.1:55554/automation/runs' \
  -H 'Content-Type: application/json' \
  -d '{"userId":3,"taskId":"uNDVKT_VwhEDuXT3PGUUv","appId":"adoFNVNN6Jwl8FlbZCfni","status":0}'
```

***

#### ▶️ Bắt đầu chạy

* **Phương thức:** `PUT`
* **Đường dẫn:** `/automation/runs/:id/run`

**Ví dụ cURL:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/runs/xhfjAeUOB5SXC8d5RiK_c/run' \
  -H 'Content-Type: application/json' \
  -d '{"deviceIds":[]}'
```

***

### 👤 API người dùng

#### 🧾 Thông tin người dùng hiện tại

* **Phương thức:** `GET`
* **Đường dẫn:** `/backend/auth/me`

**Ví dụ cURL:**

```bash
curl -X GET 'http://127.0.0.1:55554/backend/auth/me'
```

***

### 📘 Ghi chú

* Thay `:id` bằng ID thực tế của ứng dụng, nhiệm vụ hoặc lượt chạy.
* Trường `script.flow` trong cập nhật ứng dụng dùng để định nghĩa luồng logic tự động dạng sơ đồ.

***

### 📥 Tải xuống Postman Collection

{% file src="/files/PigK0JeIayvndSUWq67c" %}

### ☎️ Hỗ trợ

Nếu cần thêm trợ giúp, vui lòng liên hệ đội ngũ GenFarmer.
