📘 Multi Profile API Documentation

Tài liệu API đầy đủ cho hệ thống quản lý Profile trình duyệt

Mục lục

GET /rest/profiles
Lấy danh sách tất cả các profile trình duyệt hiện có trong hệ thống.

✅ Response - Thành công

200 Lấy danh sách thành công

{
  "success": true,
  "data": [
    {
      "id": "abc123",
      "name": "My Profile 1",
      "proxy": "http:127.0.0.1:8080:user:pass",
      "note": "Test profile",
      "status": "stopped",
      "who_running": null,
      "debug_port": null,
      ...
    },
    {
      "id": "xyz789",
      "name": "My Profile 2",
      "proxy": "socks5:127.0.0.1:9090:user:pass",
      "note": "Another profile",
      "status": "running",
      "who_running": "machine-id-123",
      "debug_port": 9222,
      ...
    }
  ],
  "message": "Lấy danh sách profile thành công"
}

💡 Ví dụ sử dụng

curl -X GET "http://127.0.0.1:5678/rest/profiles"
const response = await fetch('http://127.0.0.1:5678/rest/profiles');
const data = await response.json();
console.log(data.data); // Array of profiles
import requests

response = requests.get('http://127.0.0.1:5678/rest/profiles')
profiles = response.json()
print(profiles['data'])
GET /rest/profiles/create
Tạo một profile trình duyệt mới với các thông số cấu hình như tên, proxy, ghi chú và extension.

📋 Tham số Query

Tham số Kiểu Bắt buộc Mô tả
profile_name string Bắt buộc Tên của profile cần tạo.
proxy string Không bắt buộc Cấu hình proxy theo định dạng: http:ip:port:user:pass hoặc socks5:ip:port:user:pass hoặc ip:port:user:pass hoặc http:user:pass@ip:port hoặc socks5:user:pass@ip:port hoặc user:pass@ip:port hoặc http:ip:port hoặc socks5:ip:port hoặc ip:port
note string Không bắt buộc Ghi chú bổ sung cho profile
extension string Không bắt buộc Danh sách extension IDs hoặc đường dẫn local, ngăn cách bởi dấu xuống dòng

✅ Response - Thành công

200 Tạo profile thành công

{
  "success": true,
  "data": {
    "profile_id": "abc123"
  },
  "message": "Tạo profile thành công"
}

❌ Response - Lỗi

200 Tạo profile thất bại

{
  "success": false,
  "data": {
    "profile_id": null
  },
  "message": "Thông báo lỗi cụ thể"
}

💡 Ví dụ sử dụng

curl -X GET "http://127.0.0.1:5678/rest/profiles/create?profile_name=My%20Profile&proxy=http:127.0.0.1:8080:user:pass¬e=Test%20profile"
const response = await fetch(
  'http://127.0.0.1:5678/rest/profiles/create?' + 
  new URLSearchParams({
    profile_name: 'My Profile',
    proxy: 'http:127.0.0.1:8080:user:pass',
    note: 'Test profile'
  })
);
const data = await response.json();
console.log(data);
import requests

params = {
    'profile_name': 'My Profile',
    'proxy': 'http:127.0.0.1:8080:user:pass',
    'note': 'Test profile'
}
response = requests.get('http://127.0.0.1:5678/rest/profiles/create', params=params)
print(response.json())
PUT /rest/profiles/:id
Cập nhật thông tin của một profile đã tồn tại, bao gồm proxy và ghi chú.

📋 Tham số URL

Tham số Kiểu Bắt buộc Mô tả
id string Bắt buộc ID của profile cần cập nhật

📋 Request Body

Tham số Kiểu Bắt buộc Mô tả
proxy string Không bắt buộc Cấu hình proxy mới. Để trống để xóa proxy hiện tại.
note string Không bắt buộc Ghi chú mới. Nếu không gửi, giữ nguyên ghi chú cũ.

✅ Response - Thành công

200 Cập nhật thành công

{
  "success": true,
  "data": {
    "id": "abc123",
    "name": "My Profile",
    "proxy": "http:127.0.0.1:8080:user:pass",
    "note": "Updated note",
    ...
  },
  "message": "Cập nhật profile thành công"
}

❌ Response - Lỗi

200 Cập nhật thất bại

{
  "success": false,
  "message": "Có lỗi xảy ra khi cập nhật profile"
}

💡 Ví dụ sử dụng

curl -X PUT "http://127.0.0.1:5678/rest/profiles/abc123" \
  -H "Content-Type: application/json" \
  -d '{
    "proxy": "http:127.0.0.1:9090:newuser:newpass",
    "note": "Updated profile"
  }'
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123', {
  method: 'PUT',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    proxy: 'http:127.0.0.1:9090:newuser:newpass',
    note: 'Updated profile'
  })
});
const data = await response.json();
console.log(data);
import requests

data = {
    'proxy': 'http:127.0.0.1:9090:newuser:newpass',
    'note': 'Updated profile'
}
response = requests.put('http://127.0.0.1:5678/rest/profiles/abc123', json=data)
print(response.json())
DELETE /rest/profiles/:id
Xóa vĩnh viễn một profile và tất cả dữ liệu liên quan.

📋 Tham số URL

Tham số Kiểu Bắt buộc Mô tả
id string Bắt buộc ID của profile cần xóa

✅ Response - Thành công

200 Xóa thành công

{
  "success": true,
  "message": "Xóa profile thành công"
}

❌ Response - Lỗi

200 Xóa thất bại

{
  "success": false,
  "message": "Có lỗi xảy ra khi xóa profile"
}
⚠️ Lưu ý

Thao tác xóa profile là không thể hoàn tác. Hãy chắc chắn bạn muốn xóa profile trước khi thực hiện.

💡 Ví dụ sử dụng

curl -X DELETE "http://127.0.0.1:5678/rest/profiles/abc123"
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123', {
  method: 'DELETE'
});
const data = await response.json();
console.log(data);
import requests

response = requests.delete('http://127.0.0.1:5678/rest/profiles/abc123')
print(response.json())
GET /rest/profiles/:id/run
Khởi động một profile trình duyệt với các tùy chọn về vị trí cửa sổ, kích thước và tỷ lệ hiển thị.

📋 Tham số URL

Tham số Kiểu Bắt buộc Mô tả
id string Bắt buộc ID của profile cần chạy

📋 Tham số Query

Tham số Kiểu Bắt buộc Mô tả
win_scale string Không bắt buộc Tỷ lệ zoom của cửa sổ (ví dụ: "1", "1.25")
win_pos string Không bắt buộc Vị trí cửa sổ theo định dạng "x,y" (ví dụ: "100,100")
win_size string Không bắt buộc Kích thước cửa sổ theo định dạng "width,height" (ví dụ: "1024,768")
source string Không bắt buộc Chú ý: Truyền source="node" để tối ưu khi chạy automation, khi chạy profile từ giao diện thì để trống

✅ Response - Thành công

200 Chạy profile thành công

{
  "success": true,
  "data": {
    "wsUrl": "ws://127.0.0.1:9222/devtools/browser/...",
    "pid": 12345,
    "debugPort": 9222,
    "exePath": "C:\\path\\to\\chrome.exe",
    "userDataDir": "C:\\path\\to\\profile\\data"
  },
  "message": "OK"
}

❌ Response - Lỗi

200 Chạy profile thất bại

{
  "success": false,
  "message": "Có lỗi xảy ra khi chạy profile"
}

💡 Ví dụ sử dụng

curl -X GET "http://127.0.0.1:5678/rest/profiles/abc123/run?win_scale=1.25&win_pos=100,100&win_size=1024,768&source=node"
const params = new URLSearchParams({
  win_scale: '1.25',
  win_pos: '100,100',
  win_size: '1024,768',
  source: 'node'
});

const response = await fetch(
  `http://127.0.0.1:5678/rest/profiles/abc123/run?${params}`
);
const data = await response.json();
console.log(data);
import requests

params = {
    'win_scale': '1.25',
    'win_pos': '100,100',
    'win_size': '1024,768',
    'source': 'node'
}
response = requests.get('http://127.0.0.1:5678/rest/profiles/abc123/run', params=params)
print(response.json())
GET /rest/profiles/:id/stop
Dừng một profile trình duyệt đang chạy. Profile chỉ có thể dừng nếu đang chạy trên chính máy này.

📋 Tham số URL

Tham số Kiểu Bắt buộc Mô tả
id string Bắt buộc ID của profile cần dừng

✅ Response - Thành công

200 Dừng profile thành công

{
  "success": true,
  "message": "Đóng thành công, profile id: abc123"
}

❌ Response - Lỗi

200 Các trường hợp lỗi

// Profile không tồn tại
{
  "success": false,
  "message": "Không tìm thấy profile"
}

// Profile không đang chạy
{
  "success": false,
  "message": "Profile không đang chạy"
}

// Profile đang chạy trên máy khác
{
  "success": false,
  "message": "Profile đang chạy trên máy khác"
}

// Lỗi khác
{
  "success": false,
  "message": "Có lỗi xảy ra khi đóng profile"
}
⚠️ Lưu ý

API này kiểm tra statuswho_running của profile để đảm bảo chỉ có thể dừng profile đang chạy trên chính máy gọi API.

💡 Ví dụ sử dụng

curl -X GET "http://127.0.0.1:5678/rest/profiles/abc123/stop"
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123/stop');
const data = await response.json();
console.log(data);
import requests

response = requests.get('http://127.0.0.1:5678/rest/profiles/abc123/stop')
print(response.json())
POST /rest/profiles/:id/import-cookies
Import cookies vào một profile. Cookies sẽ được merge với cookies hiện tại của profile. Nếu profile đang chạy trên máy này, cookies sẽ được load ngay vào trình duyệt.

📋 Tham số URL

Tham số Kiểu Bắt buộc Mô tả
id string Bắt buộc ID của profile cần import cookies

📋 Request Body

Tham số Kiểu Bắt buộc Mô tả
cookies string Bắt buộc Chuỗi JSON chứa danh sách cookies cần import

📝 Định dạng Cookies

Cookies phải là một mảng JSON với mỗi phần tử chứa thông tin cookie:

[
  {
    "name": "session_id",
    "value": "abc123xyz",
    "domain": ".example.com",
    "path": "/",
    "secure": true,
    "httpOnly": true,
    "expirationDate": 1735689600
  },
  ...
]

✅ Response - Thành công

200 Import thành công

{
  "success": true,
  "message": "Cookies đã được import và merge thành công"
}

❌ Response - Lỗi

200 Import thất bại

// Profile không tồn tại
{
  "success": false,
  "message": "Profile không tồn tại"
}

// Định dạng cookies không hợp lệ
{
  "success": false,
  "message": "Định dạng cookies không hợp lệ"
}

// Lỗi khác
{
  "success": false,
  "message": "Có lỗi xảy ra khi import cookies"
}
💡 Lưu ý

- Cookies sẽ được merge với cookies hiện có, không ghi đè hoàn toàn.
- Nếu profile đang chạy trên máy này, cookies sẽ được load ngay vào trình duyệt thông qua debug port.
- Cookies được validate trước khi import.

💡 Ví dụ sử dụng

curl -X POST "http://127.0.0.1:5678/rest/profiles/abc123/import-cookies" \
  -H "Content-Type: application/json" \
  -d '{
    "cookies": "[{\"name\":\"session_id\",\"value\":\"abc123\",\"domain\":\".example.com\"}]"
  }'
const cookies = [
  {
    name: 'session_id',
    value: 'abc123',
    domain: '.example.com',
    path: '/',
    secure: true
  }
];

const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123/import-cookies', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    cookies: JSON.stringify(cookies)
  })
});
const data = await response.json();
console.log(data);
import requests
import json

cookies = [
    {
        'name': 'session_id',
        'value': 'abc123',
        'domain': '.example.com',
        'path': '/',
        'secure': True
    }
]

data = {
    'cookies': json.dumps(cookies)
}
response = requests.post(
    'http://127.0.0.1:5678/rest/profiles/abc123/import-cookies', 
    json=data
)
print(response.json())
GET /rest/profiles/:id/export-cookies
Export cookies từ một profile. Nếu profile đang chạy trên máy này, cookies sẽ được lấy trực tiếp từ trình duyệt. Ngược lại, lấy từ database.

📋 Tham số URL

Tham số Kiểu Bắt buộc Mô tả
id string Bắt buộc ID của profile cần export cookies

✅ Response - Thành công

200 Export thành công

{
  "success": true,
  "data": [
    {
      "name": "session_id",
      "value": "abc123xyz",
      "domain": ".example.com",
      "path": "/",
      "secure": true,
      "httpOnly": true,
      "expirationDate": 1735689600
    },
    ...
  ]
}

❌ Response - Lỗi

200 Export thất bại

// Không có cookies để export
{
  "success": false,
  "message": "Không có cookies để export"
}

// Lỗi khác
{
  "success": false,
  "message": "Chi tiết lỗi"
}
💡 Lưu ý

- Nếu profile đang chạy (status === 'running') và trên máy này (who_running === machineId), cookies được lấy từ trình duyệt qua debug port.
- Ngược lại, cookies được lấy từ trường cookies trong database.

💡 Ví dụ sử dụng

curl -X GET "http://127.0.0.1:5678/rest/profiles/abc123/export-cookies"
const response = await fetch('http://127.0.0.1:5678/rest/profiles/abc123/export-cookies');
const result = await response.json();
if (result.success) {
  console.log(result.data); // Array of cookies
} else {
  console.error(result.message);
}
import requests

response = requests.get('http://127.0.0.1:5678/rest/profiles/abc123/export-cookies')
result = response.json()
if result['success']:
    cookies = result['data']
    print(cookies)
else:
    print(result['message'])