API 參考

帳號授權

建立渠道授權會話

為 auth_mode=qrcode 的 WhatsApp 帳號建立短期託管授權會話。請在使用者瀏覽器開啟 authorize_url,並將完整 URL 視為敏感憑證,切勿記錄或分享。

POSThttps://api.unifyport.ai/v1/accounts/{account_id}/auth-sessions

支援渠道

WhatsApp

呼叫前準備

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

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

請求參數

請求標頭

X-Api-Key
string必填

工作區 API Key,工作區會由此標頭解析得到。

路徑參數

account_id
string必填

用於該 authentication 路由的識別字。

請求內容

此介面無需 JSON 請求內容。

如何理解結果

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

回應 201 Created

{
  "request_id": "<REQUEST_ID>",
  "data": {
    "account_id": "acc_example",
    "provider": "whatsapp",
    "auth_mode": "qrcode",
    "status": "passkey_required",
    "auth_payload": {
      "type": "passkey",
      "public_key": {
        "challenge": "<BASE64URL_CHALLENGE>"
      }
    },
    "authorize_url": "https://auth.example.com/authorize/whatsapp/<SESSION_TOKEN>",
    "expires_at": "2026-08-12T08:10:00Z",
    "switchable": false,
    "available_auth_modes": [
      "qrcode"
    ]
  }
}

回應內容

account_id
string

本回應所對應的渠道帳號。

provider
string

管道識別碼。呼叫其他介面時原樣使用 API 回傳的值;此介面的回傳範圍請看下方列舉。

enum: whatsapp

auth_mode
string

此授權會話的認證模式;目前為 qrcode。

status
string

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

auth_payload
object

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

authorize_url
string

包含不透明憑證的短期託管授權 URL,切勿記錄或分享完整值。

format: uri

expires_at
string

RFC3339 時間戳記,超過後當前的 auth_payload 即失效。

format: date-time

switchable
boolean

託管授權會話是否允許使用者切換認證模式。

available_auth_modes[]
string[]

託管授權會話中可用的認證模式。

回應

201

201 Created

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

400

請求錯誤

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

401

未授權

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

403

禁止存取

請求已識別,但不允許執行此操作。

404

找不到資源

找不到請求的資源;請結合 error.code 和目前操作核對。

409

衝突

目前操作與既有的渠道帳號或資源衝突。

500

伺服器錯誤

服務遇到了未預期的錯誤。

503

服務無法使用

所需的後端服務暫時無法使用。

失敗後如何處理

檢查 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"
  }
}
unsupported_provider_auth_mode · 20018 · 400

請使用此管道支援的 auth_mode。

處理與重試: 選擇文件列為支援的渠道與動作。重複請求不會增加能力或開通內測權限。

示意 JSON;message 隨實際原因變化 · 400 · 20018
{
  "request_id": "req_example",
  "error": {
    "code": "unsupported_provider_auth_mode",
    "numeric_code": "20018",
    "message": "Auth mode not supported by this provider"
  }
}
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"
  }
}
egress_configuration_pending · 20032 · 409

目前無法確認或讀取平台預設網路設定;這不代表帳號已登出。

觸發條件: 此操作使用平台分配的網路容量或帳號固定的預設網路設定。

處理與重試: 保留 request_id,再次寫入前確認帳號或建立結果。等待容量或設定恢復,或聯絡支援;不要自動反覆建立帳號、更換網路或重新啟動帳號。

示意 JSON;message 隨實際原因變化 · 409 · 20032
{
  "request_id": "req_example",
  "error": {
    "code": "egress_configuration_pending",
    "numeric_code": "20032",
    "message": "Account network configuration is pending verification"
  }
}
provider_not_ready · 30009 · 409

連線尚未就緒,請檢查授權及 runtime_status 後再決定是否重試。

處理與重試: 查詢授權與執行狀態,再按目標狀態和渠道支援選擇重新整理、啟動或重新連線。連線問題本身不證明已登出;執行依賴連線的業務操作前確認 running。

示意 JSON;message 隨實際原因變化 · 409 · 30009
{
  "request_id": "req_example",
  "error": {
    "code": "provider_not_ready",
    "numeric_code": "30009",
    "message": "Provider client is not ready"
  }
}
run_auth_action_failed · 20010 · 500

執行授權動作:授權動作失敗,需檢查既有流程,不代表必須重新授權。

處理與重試: 查詢目前授權流程,檢查是否需要使用者操作。不要僅因本次失敗重新發起授權,也不要向已過期或已結束的工作階段重複提交。

示意 JSON;message 隨實際原因變化 · 500 · 20010
{
  "request_id": "req_example",
  "error": {
    "code": "run_auth_action_failed",
    "numeric_code": "20010",
    "message": "Failed to run auth action"
  }
}
run_auth_action_failed · 20020 · 500

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

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

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

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

本次請求所需的授權工作階段服務暫不可用或未設定。聯絡服務方檢查授權工作階段服務。

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

示意 JSON;message 隨實際原因變化 · 503 · 11006
{
  "request_id": "req_example",
  "error": {
    "code": "internal_auth_not_configured",
    "numeric_code": "11006",
    "message": "Internal endpoint authentication is not configured"
  }
}