> For the complete documentation index, see [llms.txt](https://docs.verge.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verge.io/knowledge-base/vi/automation-api/api-helper-script.md).

# Script trợ giúp API

Tham số `yb-api` Script trợ giúp cung cấp cho các nhà phát triển một cách dễ dàng để tương tác với API VergeOS. Nó đơn giản hóa việc thực hiện các lệnh gọi API, chẳng hạn như truy xuất máy ảo, cập nhật cấu hình và quản lý tài nguyên. Hướng dẫn này sẽ trình bày các lệnh chính và cách sử dụng của `yb-api` script.

## Điều kiện tiên quyết

* Quyền truy cập vào một hệ thống VergeOS.
* Quyền truy cập vào cụm qua SSH hoặc kết nối trực tiếp.
* **wget** và **curl** phải được cài đặt trên hệ thống cho một số thao tác nhất định.

### Chạy Script Trợ Giúp

Để nhận trợ giúp hoặc xem các tùy chọn khả dụng, hãy chạy:

```bash
yb-api --help
```

Kết nối vào node và thực thi lệnh này để bắt đầu sử dụng trình trợ giúp API.

![Ví dụ yb-api](/files/57ddf7551220b3a528902fad6e6c935d1660ffa4)

## Các lệnh ví dụ

Dưới đây là các ví dụ về cách sử dụng `yb-api` cho nhiều tác vụ quản lý VM khác nhau.

### Lấy danh sách máy ảo (không bao gồm snapshot)

Truy xuất danh sách VM và lọc bỏ các snapshot.

```bash
yb-api --get --user=admin --server=10.0.0.100 \
--fields='name,$key,ram,machine#status#status as machine_status' \
--filter='is_snapshot eq false' /v4/vms
```

### Xuất đơn giản tất cả VM

Lệnh này truy xuất danh sách tất cả VM. Các `--server`, `--user`, `--filter`, và `--fields` cờ này là tùy chọn trong trường hợp này.

```bash
yb-api --get /v4/vms
```

### Lấy thông tin chi tiết về VM

Truy xuất hầu hết các trường, bao gồm thông tin về ổ đĩa và NIC, cho một VM cụ thể (ở đây là VM 1).

```bash
yb-api --get --user=admin --server=10.0.0.100 \
--fields='most,machine[most,drives[most],nics[most]]' /v4/vms/1
```

### Đổi tên một máy ảo

Đổi tên một máy ảo hiện có (VM 1) thành "NEWNAME".

```bash
yb-api --put='{"name":"NEWNAME"}' --user=admin --server=10.0.0.100 /v4/vms/1
```

### Xóa một máy ảo

Xóa một VM cụ thể (VM 1), sử dụng `$key`.

```bash
yb-api --delete --user=admin --server=10.0.0.100 \
--fields='name,$key,ram' /v4/vms/1
```

### Tạo một máy ảo mới

Tạo một VM mới với cấu hình cụ thể (tên, số lõi CPU, RAM, v.v.).

```bash
yb-api --post='{"name":"NEWVM","enabled":true,"description":"test vm",\
"os_family":"linux","cpu_cores":4,"ram":"8192"}' --user=admin \
--server=10.0.0.100 /v4/vms
```

### Lấy lược đồ bảng cơ sở dữ liệu VM

Truy xuất lược đồ cho bảng cơ sở dữ liệu VM.

```bash
yb-api --get --user=admin --server=10.0.0.100 '/v4/vms/$table'
```

### Nhân bản một máy ảo

Nhân bản một VM hiện có (VM 1) và đặt cho nó một tên mới.

```bash
yb-api --get --user=admin --server=10.0.0.100 '/v4/vm_actions' \
--post='{"vm":1, "action": "clone", "params": {"name": "NEW VM NAME"}}'
```

### Bật nguồn một máy ảo

Bật nguồn một VM hiện có (VM 1).

```bash
yb-api --get --user=admin --server=10.0.0.100 '/v4/vm_actions' \
--post='{"vm":1, "action": "poweron"}'
```

## Lưu ý về `yb-api`

* Tham số `yb-api` script phụ thuộc vào **wget**, điều này có thể không được cài đặt theo mặc định trên macOS. Hãy đảm bảo cài đặt nó nếu cần.
* **curl** được dùng cho chức năng tải lên trong một số lệnh gọi API nhất định, chẳng hạn như gửi dữ liệu để tạo máy ảo mới.

***

Bằng cách sử dụng `yb-api` script trợ giúp, các nhà phát triển có thể đơn giản hóa việc tương tác với API VergeOS và quản lý máy ảo hiệu quả hơn. Hãy cho chúng tôi biết nếu bạn cần hỗ trợ thêm về các lệnh hoặc tùy chọn khác.

***

{% hint style="info" %}
**Thông tin tài liệu**

* Cập nhật lần cuối: 2024-08-29
* Phiên bản vergeOS: 4.12.6
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.verge.io/knowledge-base/vi/automation-api/api-helper-script.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
