API 參考

帳號授權

建立渠道授權會話

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

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

呼叫前準備

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

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

請求參數

請求標頭

X-Api-Key
string必填

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

路徑參數

account_id
string必填

用於該 authentication 路由的識別字。

請求內容

此介面無需 JSON 請求內容。

如何理解結果

依文件解讀回應欄位與 HTTP 狀態。204 成功沒有回應本文,排查時使用 X-Request-Id。下一步請參閱相關操作。

回應 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。互斥步驟的載荷不會同時出現。

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 請求標頭缺少或無效。

500

伺服器錯誤

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

503

服務無法使用

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

失敗後如何處理

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

invalid_request · 10000 · 400
檢查必填欄位、格式與渠道條件,修正請求後再呼叫。
invalid_api_key · 11001 · 401
檢查 X-Api-Key 與工作區是否有效。