Stacking — Register#
Worker auth service account vào Google Drive folder đã được assign tạo sẵn. Giai đoạn này xác nhận service account có quyền truy cập folder và sẵn sàng tạo file.
Base URL: https://manager.likepion.com/api/v1/stacking
1. Lấy danh sách task #
# Không gửi status → trả cả register + connect (worker tự xử lý theo status từng task)
curl -X GET 'https://manager.likepion.com/api/v1/stacking/links?limit=5' \
-H 'X-API-Key: <api_key>'
# Lọc riêng từng phase (tuỳ chọn):
curl -X GET 'https://manager.likepion.com/api/v1/stacking/links?limit=5&status=register' \
-H 'X-API-Key: <api_key>'| Param | Mặc định | Mô tả |
|---|---|---|
limit | 5 | Số task muốn pull (tối đa 1000) |
status | (cả register + connect) | Lọc theo trạng thái task. Không gửi → trả về cả 2 phase. Gửi register chỉ task phase 1, gửi connect chỉ task phase 2 (auth xong, đang chờ tạo file). |
💡 Khuyến nghị: Worker nên KHÔNG gửi
statusđể pull cả 2 phase, sau đó dispatch dựa vào fieldstatustrong từng task response. Tránh phải gọi 2 endpoint riêng cho register/connect.
Response#
{
"success": true,
"data": [
{
"id": "c5d8e912-3a4b-5c6d-7e8f-abc123def456",
"request_id": "f37e0e54-d93a-4b06-98cc-1002301c696c",
"status": "register",
"domain": "docs.google.com",
"website": "https://likepion.com",
"title": "Dịch vụ SEO chuyên nghiệp 2026",
"about": "<p>Nội dung bài viết...</p>",
"phone": "0987654321",
"address": "123 ABC",
"location": "Ha Noi",
"image_url": "https://s3.likepion.com/stack/cover.jpg",
"folder_id": "1AiNsOTpmIlINZa_2QaXmpQxOGLNEAz2a",
"link_post": ""
}
]
}Giải thích fields#
| Field | Mô tả |
|---|---|
id | ID task — dùng khi gọi start/complete/fail |
request_id | ID request cha |
status | Trạng thái hiện tại (register) |
domain | Nền tảng Drive (docs.google.com, slides.google.com, sheets.google.com) |
website | Website khách hàng (anchor backlink trỏ về đây) |
title | Tiêu đề file Drive |
about | Nội dung bài viết HTML (đã xử lý spin) |
phone | Số điện thoại chèn vào file |
address | Địa chỉ chèn vào file |
location | Vị trí / thành phố |
image_url | S3 URL ảnh insert vào file Drive |
folder_id | ID folder Drive assign chỉ định cho task này |
link_post | URL Drive folder đã tạo — chuỗi rỗng "" nếu chưa complete lần nào (retry từ profile_failed sẽ có giá trị) |
2. Lấy chi tiết task #
Lấy thông tin 1 task cụ thể theo id. Không cần filter server/status. Không thay đổi DB.
curl -X GET 'https://manager.likepion.com/api/v1/stacking/links/TASK_ID' \
-H 'X-API-Key: <api_key>'Response#
Trả về 1 object (không bọc trong mảng) — schema giống bước 1.
{ "success": true, "data": { ...task fields... } }Nếu task không tồn tại hoặc đã soft-delete → HTTP 404 {"success": false, "message": "task not found"}.
3. Báo đang xử lý #
Sau khi pull task, bắt buộc gọi API này để chuyển task từ register → registering.
| Trạng thái trước | Trạng thái sau |
|---|---|
register | registering |
Lưu ý: API chỉ chấp nhận task có
status = register. Task ở trạng thái khác sẽ bị từ chối.
curl -X POST 'https://manager.likepion.com/api/v1/stacking/links/<task_id>/start' \
-H 'X-API-Key: <api_key>'Response#
{ "success": true }4. Báo hoàn thành #
Báo register thành công — task chuyển từ registering → profiled. Worker cần hoàn tất auth service account + tạo file Drive + điền nội dung + backlink trong 1 lần call (stacking không có intermediate auth-only).
| Trạng thái trước | Trạng thái sau |
|---|---|
registering | profiled |
Assign barrier per-folder: khi tất cả task trong CÙNG 1 folder_id đã thoát phase 1 (profiled / final_failed / cancel), batch transition profiled → connect cho riêng folder đó — không đợi folder khác. Mỗi Link Folder tiến độ độc lập. Request-level flip sang connecting khi mọi folder đều đã phase 2.
Lưu ý:
link_postchính là URL của Google Drive folder (https://drive.google.com/drive/folders/<id>).
curl -X POST 'https://manager.likepion.com/api/v1/stacking/links/<task_id>/complete' \
-H 'X-API-Key: <api_key>' \
-H 'Content-Type: application/json' \
-d '{
"link_post": "https://drive.google.com/drive/folders/1AiNsOTpmIlINZa_2QaXmpQxOGLNEAz2a",
"note": "auth + files created"
}'| Field | Bắt buộc | Mô tả |
|---|---|---|
link_post | ✔ | URL folder Google Drive |
note | Ghi chú (tuỳ chọn) |
Response#
{ "success": true }5. Báo thất bại #
Task chuyển từ registering → profile_failed. Retry manager tự re-queue nếu còn retry_count < max_retries.
| Trạng thái trước | Trạng thái sau |
|---|---|
registering | profile_failed |
curl -X POST 'https://manager.likepion.com/api/v1/stacking/links/<task_id>/fail' \
-H 'X-API-Key: <api_key>' \
-H 'Content-Type: application/json' \
-d '{
"error_message": "Drive quota exceeded when creating doc",
"note": "auth_ok_but_file_creation_failed"
}'| Field | Bắt buộc | Mô tả |
|---|---|---|
error_message | ✔ | Mô tả ngắn lỗi (≤1000 ký tự) |
note | Ghi chú thêm |
Response#
{ "success": true }6. Check trạng thái folder #
Check xem folder đã có task nào chuyển sang phase connect chưa. Worker poll endpoint này trước khi pull task phase 2 — nếu ready=false thì chưa cần gọi /stacking/links?status=connect.
Chỉ đếm task được gán cho server đang gọi (filter theo X-API-Key).
curl -X GET 'https://manager.likepion.com/api/v1/stacking/folders/1AiNsOTpmIlINZa_2QaXmpQxOGLNEAz2a/connect-status' \
-H 'X-API-Key: <api_key>'Response#
{
"success": true,
"folder_id": "1AiNsOTpmIlINZa_2QaXmpQxOGLNEAz2a",
"ready": true,
"total_tasks": 11,
"phase1_active": 0,
"profiled": 0,
"connect_count": 9,
"by_status": {
"connect": 9,
"final_failed": 2
}
}| Field | Mô tả |
|---|---|
ready | true nếu đã có ≥1 task status ∈ (connect / connecting / connect_failed) — folder đã bước phase 2 |
total_tasks | Tổng task của folder này thuộc server đang gọi |
phase1_active | Task còn ở phase 1 (pending/queued/running/register/registering/profile_failed/…) — chưa xong barrier |
profiled | Task đã profiled, chờ completer transition sang connect |
connect_count | Task đã ở phase 2 |
by_status | Breakdown chi tiết theo từng status |
Lỗi:
| Code | Mô tả |
|---|---|
| 400 | Thiếu folder_id trong path |
403 service_key_mismatch | API key không thuộc server có service google_stacking / stacking |
403 server_not_online | Server đang offline — gọi /worker/health trước để hồi phục |