Automation Run API#

API chạy và theo dõi automation. Hỗ trợ SSE (Server-Sent Events) để theo dõi realtime.

Base URL: https://app.socialking.vn/api/v1


1. Chạy Automation#

POST /automation/run/:id/start #

Auth: Bearer Token (JWT)

Rate Limit: 5 req/phút

URL Params:

ParamTypeMô tả
idUUIDAutomation ID

Request Body:

{
  "skipScheduleNode": true
}
FieldTypeRequiredValidation
skipScheduleNodebooleanNoDefault true, bỏ qua schedule node

Response (200):

{
  "success": true,
  "data": {
    "runId": "uuid-string",
    "automationId": "uuid-string",
    "status": "running",
    "startedAt": "2026-03-30T10:30:00Z"
  }
}

2. Dừng Automation#

POST /automation/run/:runId/stop #

Auth: Bearer Token (JWT)

Rate Limit: 10 req/phút

URL Params:

ParamTypeMô tả
runIdUUIDRun ID

Response (200):

{
  "success": true,
  "message": "Run stopped"
}

3. Xem trạng thái Run#

GET /automation/run/:runId/status #

Auth: Bearer Token (JWT)

Rate Limit: 60 req/phút

URL Params:

ParamTypeMô tả
runIdUUIDRun ID

Response (200):

{
  "success": true,
  "data": {
    "runId": "uuid-string",
    "status": "running",
    "progress": 65,
    "completedAt": null
  }
}

4. SSE - Theo dõi Realtime#

GET /automation/run/:runId/sse #

Auth: Bearer Token (JWT)

Protocol: Server-Sent Events

Response: SSE Stream

event: status
data: {"runId":"...","status":"running","progress":30,"message":"Processing..."}

event: status
data: {"runId":"...","status":"completed","progress":100,"message":"Done"}

5. Danh sách Run đang chạy#

GET /automation/run/active #

Auth: Bearer Token (JWT)

Rate Limit: 30 req/phút

Query Parameters:

ParamTypeDefaultMô tả
_limitnumber10Số lượng items

Response (200):

{
  "success": true,
  "data": [
    {
      "runId": "uuid-string",
      "automationId": "uuid-string",
      "status": "running",
      "startedAt": "2026-03-30T10:30:00Z"
    }
  ]
}

6. Lịch sử Run#

GET /automation/run/history #

Auth: Bearer Token (JWT)

Rate Limit: 30 req/phút

Query Parameters:

ParamTypeDefaultMô tả
_pagenumber1Trang
_limitnumber101-100 items/trang
_orderstringdescasc | desc
_statusstringallall | pending | running | success | failed | canceled | skipped
_fbAutomationIdUUID-Required - Automation ID
_triggeredBystringallall | manual | schedule | api

Response (200):

{
  "success": true,
  "data": {
    "runs": [
      {
        "runId": "uuid-string",
        "automationId": "uuid-string",
        "status": "success",
        "triggeredBy": "manual",
        "startedAt": "2026-03-30T10:30:00Z",
        "completedAt": "2026-03-30T10:35:00Z"
      }
    ],
    "total": 42,
    "page": 1
  }
}