Bỏ qua để đến nội dung

API tự động hóa

MyPanel có REST API dùng chính cho giao diện. Trang này liệt kê tập endpoint ổn định, hữu ích cho tự động hóa (CI/CD, script vận hành). Xác thực bằng API token (gói Pro).

Mọi request gửi kèm header:

Authorization: Bearer mpat_xxxxxxxx

Base URL là địa chỉ panel của bạn, ví dụ https://panel.example.com. Các ví dụ dưới dùng hai biến:

Terminal window
PANEL=https://panel.example.com
TOKEN=mpat_xxxxxxxx
Terminal window
# Liệt kê website
curl -H "Authorization: Bearer $TOKEN" $PANEL/api/sites
# Tạo website (reverse proxy / static / nixpacks / dockerfile / image / wordpress)
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"domain":"app.example.com","buildKind":"reverseproxy","source":"http://127.0.0.1:3000"}' \
$PANEL/api/sites
# Triển khai (deploy) website theo id
curl -X POST -H "Authorization: Bearer $TOKEN" $PANEL/api/sites/1/deploy
# Xem trạng thái lần triển khai gần nhất
curl -H "Authorization: Bearer $TOKEN" $PANEL/api/sites/1/deployment
# Xóa website
curl -X DELETE -H "Authorization: Bearer $TOKEN" $PANEL/api/sites/1
Terminal window
# Liệt kê database
curl -H "Authorization: Bearer $TOKEN" $PANEL/api/databases
# Tạo database
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{"engine":"MySQL","name":"app_prod"}' $PANEL/api/databases
# Tạo bản backup ngay cho database theo id
curl -X POST -H "Authorization: Bearer $TOKEN" $PANEL/api/databases/1/backups
Terminal window
# Thông tin server (hostname, OS, uptime, tải, phiên bản)
curl -H "Authorization: Bearer $TOKEN" $PANEL/api/system
# Trạng thái cập nhật (phiên bản hiện tại / mới nhất)
curl -H "Authorization: Bearer $TOKEN" $PANEL/api/update
Ý nghĩa
200 / 201 / 202 / 204Thành công
400Dữ liệu gửi lên không hợp lệ
401Token sai hoặc thiếu
402Vượt giới hạn gói (kèm {"upgrade":"pro"})
403Không đủ quyền
404Không tìm thấy tài nguyên