Worker API (LIKEPION)#

API cho tool servers giao tiếp với hệ thống LIKEPION: heartbeat, lấy tasks, cập nhật trạng thái, gửi logs.

Base URL: https://apitest.likepion.com/api/v1/worker

Authentication#

Tất cả endpoints yêu cầu header:

X-API-Key: <server_api_key>

API key được lấy từ bảng servers trong database. Server phải có trạng thái online hoặc active để hoạt động.


Endpoints#

1. POST /health — Heartbeat #

Tool server gọi định kỳ để báo đang hoạt động và cập nhật metrics.

curl -X POST "https://apitest.likepion.com/api/v1/worker/health" \
  -H "X-API-Key: your-server-key" \
  -H "Content-Type: application/json" \
  -d '{
    "server_name": "server-01",
    "ip": "192.168.1.100",
    "cpu_usage": 45.5,
    "ram_usage": 60.2,
    "disk_usage": 30.0,
    "active_threads": 5,
    "active_tasks": 12
  }'

Request Body:

FieldLoạiMô tả
server_namestringTên server
ipstringĐịa chỉ IP
cpu_usagefloat% CPU đang dùng
ram_usagefloat% RAM đang dùng
disk_usagefloat% Disk đang dùng
active_threadsintSố thread đang chạy
active_tasksintSố task đang xử lý

Response:

{
  "success": true,
  "data": {
    "status": "ok",
    "server_id": "uuid",
    "server_name": "server-01",
    "server_time": "2025-12-01T10:00:00Z"
  }
}

2. GET /tasks — Lấy danh sách tasks #

Lấy tasks được giao cho server. Hỗ trợ 2 kiểu phân trang.

# Offset pagination
curl "https://apitest.likepion.com/api/v1/worker/tasks?page=1&limit=100&status=pending" \
  -H "X-API-Key: your-server-key"

# Cursor pagination (nhanh hơn khi nhiều tasks)
curl "https://apitest.likepion.com/api/v1/worker/tasks?after=last-uuid&limit=100" \
  -H "X-API-Key: your-server-key"

Query Parameters:

Tham sốMặc địnhMô tả
page1Trang (offset pagination)
limit100Số lượng (tối đa 1000)
after-ID cuối trang trước (cursor pagination)
statuspending,queuedLọc theo status
service_type-Lọc theo loại service

Response:

{
  "server_id": "uuid",
  "server_name": "server-01",
  "data": [
    {
      "id": "uuid",
      "request_id": "uuid",
      "service_type": "entity",
      "site_id": "uuid",
      "site_name": "example.com",
      "email": "user@gmail.com",
      "username": "user123",
      "password": "pass",
      "about": "Bio text",
      "link_profile": "",
      "link_post": "",
      "status": "pending",
      "retry_count": 0,
      "max_retries": 3,
      "details": null,
      "started_at": null,
      "created_at": "2025-12-01T10:00:00Z",
      "request_name": "Campaign A",
      "request_website": "https://target.com",
      "type_request": "normal",
      "auction_price": 100,
      "config": "{...}"
    }
  ],
  "total": 50,
  "page": 1,
  "limit": 100,
  "next_cursor": "uuid-of-last-item"
}

3. PUT /tasks/:id — Cập nhật task đơn lẻ #

Cập nhật trạng thái và kết quả của một task. Server chỉ có thể cập nhật task được gán cho mình.

curl -X PUT "https://apitest.likepion.com/api/v1/worker/tasks/{id}" \
  -H "X-API-Key: your-server-key" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "completed",
    "link_profile": "https://example.com/profile/user123",
    "link_post": "https://example.com/post/456"
  }'

Request Body:

FieldLoạiMô tả
statusstringpending, queued, running, completed, failed, canceled
link_profilestringURL profile đã tạo
link_poststringURL bài đăng đã tạo
error_messagestringThông báo lỗi (khi failed)
notestringGhi chú
is_indexedboolĐã được index chưa

Response:

{
  "success": true,
  "data": {
    "updated": true,
    "link_id": "uuid"
  }
}

4. PUT /tasks/bulk — Cập nhật nhiều tasks #

Cập nhật tối đa 500 tasks cùng lúc.

curl -X PUT "https://apitest.likepion.com/api/v1/worker/tasks/bulk" \
  -H "X-API-Key: your-server-key" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      {
        "link_id": "uuid-1",
        "status": "completed",
        "link_profile": "https://example.com/profile/1"
      },
      {
        "link_id": "uuid-2",
        "status": "failed",
        "error_message": "Captcha failed"
      }
    ]
  }'

Response:

{
  "total": 2,
  "success": 1,
  "failed": 1,
  "results": [
    {"link_id": "uuid-1", "success": true},
    {"link_id": "uuid-2", "success": false, "error": "not_your_task"}
  ]
}

5. POST /logs — Gửi logs hàng loạt #

Gửi batch log từ worker server (tối đa 500 log entries).

curl -X POST "https://apitest.likepion.com/api/v1/worker/logs" \
  -H "X-API-Key: your-server-key" \
  -H "Content-Type: application/json" \
  -d '{
    "logs": [
      {"level": "INFO", "message": "Task started: uuid-123"},
      {"level": "ERROR", "message": "Failed to solve captcha"},
      {"level": "WARN", "message": "Slow response from site"}
    ]
  }'

Log Levels: INFO, WARN, ERROR, DEBUG

Response:

{
  "success": true,
  "created": 3
}

Callbacks#

Các endpoint callback cho worker gửi kết quả về hệ thống (trước đây ở /api/v1/callback, giờ chuyển sang /api/v1/worker/callback có API key auth).

POST /callback/link/update — Cập nhật trạng thái link #

curl -X POST "https://apitest.likepion.com/api/v1/worker/callback/link/update" \
  -H "X-API-Key: your-server-key" \
  -H "Content-Type: application/json" \
  -d '{"link_id": "uuid", "status": "running", "link_profile": "https://example.com/profile/user123"}'
FieldLoạiBắt buộcMô tả
link_iduuidID của link
statusstringKhôngTrạng thái mới
link_profilestringKhôngURL profile
link_poststringKhôngURL bài đăng
error_messagestringKhôngThông báo lỗi

POST /callback/link/complete — Hoàn thành link #

Tự động set status=completed, completed_at=now, tăng created_links trên request.

curl -X POST "https://apitest.likepion.com/api/v1/worker/callback/link/complete" \
  -H "X-API-Key: your-server-key" \
  -H "Content-Type: application/json" \
  -d '{"link_id": "uuid", "link_profile": "https://...", "link_post": "https://..."}'

POST /callback/request/status — Cập nhật trạng thái request #

curl -X POST "https://apitest.likepion.com/api/v1/worker/callback/request/status" \
  -H "X-API-Key: your-server-key" \
  -H "Content-Type: application/json" \
  -d '{"request_id": "uuid", "status": "completed"}'

POST /callback/account/status — Cập nhật trạng thái account #

curl -X POST "https://apitest.likepion.com/api/v1/worker/callback/account/status" \
  -H "X-API-Key: your-server-key" \
  -H "Content-Type: application/json" \
  -d '{"account_id": "uuid", "status": "active"}'

Task Status Flow#

pending → queued → running → completed
                           → failed → (retry) → pending
                           → canceled

Error Responses#

HTTPMô tả
400Request không hợp lệ
401API key không hợp lệ hoặc server không active
403Task không thuộc server này (not_your_task)
404Không tìm thấy resource
500Lỗi hệ thống