API 參考

帳戶授權

攞認證狀態

回傳帳號目前嘅認證流程狀態,包括 code、QR、密碼、Passkey、會話匯入或者認證終態。Passkey 狀態包括 passkey_required、passkey_pending、passkey_confirmation 同 passkey_confirmation_sent;auth_payload 可能帶 WebAuthn public_key。

GEThttps://api.unifyport.ai/v1/accounts/{account_id}/auth

支援渠道

all

呼叫前準備

在伺服器端使用資源所屬工作區的 X-Api-Key,執行範例前替換所有預留位置。

參數從哪裡取得
account_id
從建立或查詢帳號的回應取得 data.id。帳號屬於 X-Api-Key 對應的工作區。 攞帳號

請求參數

請求標頭

X-Api-Key
string必填

工作區 API Key,工作區會由呢個標頭解析得出嚟。

路徑參數

account_id
string必填

用嚟識別嗰條 authentication 路由嘅 ID。

請求內容

呢個介面唔需要 JSON 請求內容。

如何理解結果

依本次授權動作讀取 status/auth_status 和實際回傳的 auth_payload。需要使用者操作時依管道指南繼續;authorized 表示授權完成,傳送前仍須檢查 runtime_status。

回應 200 OK

{
  "request_id": "<REQUEST_ID>",
  "data": {
    "account_id": "acc_example",
    "status": "awaiting_qr_scan",
    "auth_fields": [
      {
        "type": "qr_code",
        "required": true
      }
    ],
    "auth_payload": {
      "qr_code": "https://example.com/qr"
    },
    "expires_at": "2026-01-01T00:00:00Z",
    "last_error": ""
  }
}

回應內容

account_id
string

呢個回應所指嘅渠道帳號。

status
string

目前授權流程狀態,例如 pending_auth、awaiting_qr_scan、awaiting_code、pending、passkey_required、passkey_pending、passkey_confirmation、passkey_confirmation_sent、authorized 或 failed。

auth_fields[]
object[]

講明下一步要乜嘢 — 每一項都帶住一個 type,仲有係咪必填。

type
string

下一步認證要求嘅輸入類型,例如 code 或 password。

required
boolean

呢個認證輸入係咪一定要提供。

label
string

渠道方提供嘅輸入顯示標籤(如有)。

placeholder
string

渠道方提供嘅輸入提示文字(如有)。

auth_payload
object

目前步驟所需嘅標準載荷。普通 QR 用 qr_code;驗證碼步驟用 type=code;Passkey 可能回傳 type=passkey 同 public_key,或者回傳 type=passkey_confirmation 及確認提示。互斥步驟嘅載荷唔會同時出現。TikTok session 需要互動時可能回傳 QR 或驗證碼提示;HTTP 200 唔代表授權成功。

expires_at
string

RFC3339 時間戳,過咗呢個時間之後而家個 auth_payload 就唔再有效。

format: date-time

last_error
string

最近一次認證錯誤;冇嘅話就係空字串。

回應

200

200 OK

請求成功,回應內容嘅例子如上。

400

請求錯誤

請求內容、路徑或者參數無效。

401

未授權

X-Api-Key 請求標頭缺少或者無效。

403

禁止存取

請求已識別,但唔允許執行呢個操作。

404

搵唔到資源

搵唔到請求嘅資源;請結合 error.code 同目前操作核對。

500

伺服器錯誤

服務遇到咗未預期嘅錯誤。

失敗後如何處理

檢查 HTTP 狀態和 error.code/numeric_code,保留 request_id。依原因修正參數、繼續授權或檢查狀態。重試傳送及寫入前確認上次結果,避免重複操作。 錯誤碼參考

請按目前操作一併讀取 HTTP 狀態、error.code 同 error.numeric_code。數字碼以字串處理。保留 request_id 排查;佢唔係冪等鍵或任務識別碼。

invalid_request · 10000 · 400

檢查 JSON 請求內容與必填欄位。

觸發條件: 適用於請求內容非空,但 Content-Type 唔係 application/json 嘅請求。

處理與重試: 按目前操作同渠道條件修正參數後再請求。重複提交相同嘅無效請求唔會解決錯誤。

示意 JSON;message 會隨實際原因變化 · 400 · 10000
{
  "request_id": "req_example",
  "error": {
    "code": "invalid_request",
    "numeric_code": "10000",
    "message": "Content-Type must be application/json"
  }
}
invalid_target_workspace · 11003 · 400

工作區覆寫目標為空或格式無效。請移除覆寫請求標頭,改用目標工作區所屬嘅 API Key。

觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭嘅請求。

處理與重試: 按目前操作同渠道條件修正參數後再請求。重複提交相同嘅無效請求唔會解決錯誤。

示意 JSON;message 會隨實際原因變化 · 400 · 11003
{
  "request_id": "req_example",
  "error": {
    "code": "invalid_target_workspace",
    "numeric_code": "11003",
    "message": "Invalid target workspace"
  }
}
invalid_api_key · 11001 · 401

檢查 API Key 是否正確且已啟用。

處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。

示意 JSON;message 會隨實際原因變化 · 401 · 11001
{
  "request_id": "req_example",
  "error": {
    "code": "invalid_api_key",
    "numeric_code": "11001",
    "message": "Invalid API key"
  }
}
missing_api_key · 11000 · 401

請加入 X-Api-Key 請求標頭。

處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。

範例 · 401 · 11000
{
  "request_id": "req_xxx",
  "error": {
    "code": "missing_api_key",
    "numeric_code": "11000",
    "message": "Missing X-Api-Key header"
  }
}
workspace_override_forbidden · 11002 · 403

請求嘗試使用呢個 API Key 無權使用嘅工作區覆寫。請移除覆寫請求標頭,改用目標工作區所屬嘅 API Key。

觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭嘅請求。

處理與重試: 保留 request_id 同結構化錯誤碼,先排查目前操作,再決定下一步。

示意 JSON;message 會隨實際原因變化 · 403 · 11002
{
  "request_id": "req_example",
  "error": {
    "code": "workspace_override_forbidden",
    "numeric_code": "11002",
    "message": "Workspace override is not allowed"
  }
}
target_workspace_not_found · 11004 · 404

覆寫指定嘅工作區不存在或不可用。請核對工作區歸屬,移除覆寫請求標頭並使用目標工作區 API Key;重複請求唔會增加存取權限。

觸發條件: 適用於帶有 X-Workspace-Id 工作區覆寫請求標頭嘅請求。

處理與重試: 核對目標識別碼、資源歸屬同目前工作區。唔好將已確認缺少或無法存取嘅目標當成暫時服務故障自動重試。

示意 JSON;message 會隨實際原因變化 · 404 · 11004
{
  "request_id": "req_example",
  "error": {
    "code": "target_workspace_not_found",
    "numeric_code": "11004",
    "message": "Target workspace not found"
  }
}
get_auth_state_failed · 20006 · 500

攞認證狀態:服務未能產生有效嘅查詢結果。

處理與重試: 保留 request_id,核對目標識別碼同帳號存取範圍。查明原因後再試查詢;查詢失敗唔代表結果為空或資源不存在。

示意 JSON;message 會隨實際原因變化 · 500 · 20006
{
  "request_id": "req_example",
  "error": {
    "code": "get_auth_state_failed",
    "numeric_code": "20006",
    "message": "Failed to get account auth state"
  }
}
get_auth_state_failed · 20020 · 500

核對 account_id,並使用帳號所屬工作區的 X-Api-Key。此工作區下未找到的帳號無法使用目前 Key 存取。

觸發條件: 適用於帳號不存在嘅情況;保留原 HTTP 狀態同操作 code,透過 numeric_code 細分帳號缺失。

處理與重試: 核對目標識別碼、資源歸屬同目前工作區。唔好將已確認缺少或無法存取嘅目標當成暫時服務故障自動重試。

示意 JSON;message 會隨實際原因變化 · 500 · 20020
{
  "request_id": "req_example",
  "error": {
    "code": "get_auth_state_failed",
    "numeric_code": "20020",
    "message": "Account not found"
  }
}