API 參考

帳戶授權

匯入會話

透過匯入現有嘅 session URL 或者 cookie/會話內容完成認證。客戶端示例請用佔位符,千祈唔好喺 log 入面暴露真實會話內容。

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

呼叫前準備

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

WhatsApp Protocol 是獨立管道,使用 provider=whatsapp-protocol。目前僅支援工作階段匯入(auth_mode=session),透過既有工作階段憑證完成授權。 WhatsApp Protocol 接入授權

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

請求參數

請求標頭

X-Api-Key
string必填

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

Content-Type
string必填

發送 JSON 請求內容嘅時候請用 application/json。

路徑參數

account_id
string必填

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

請求內容

session_url
string

現有渠道會話嘅 URL 或者參考。

format: uri

whatsapp-protocol
object

WhatsApp Protocol 會話匯入憑證,只可以透過呢個巢狀物件提交至 /v1/accounts/{account_id}/auth/session,唔可以透過 provider_data 提交。提供呢個物件時,phone、static_pub_key、static_pri_key、identity_pub_key 同 identity_pri_key 必填。回應唔會回傳協議金鑰或其他敏感憑證。phone 用於身份一致性校驗;協議公鑰、私鑰只供上游啟動使用。edge_routing 由平台固定注入,唔可以提交。

phone
string

電話號碼可以包含空格、連字號、括號或加號;伺服器會歸一化為正數字串。

minLength: 1

platform
integer

WhatsApp Protocol 會話匯入嘅平台值(int32)。

format: int32

app_version
string

WhatsApp Protocol 會話匯入嘅應用程式版本。

server_address
string

WhatsApp Protocol 會話匯入嘅渠道伺服器地址。

fallback_server_addresses[]
string[]

WhatsApp Protocol 會話匯入嘅後備伺服器地址列表。

country
string

WhatsApp Protocol 會話匯入嘅國家代碼。

device
integer

WhatsApp Protocol 會話匯入嘅裝置值(uint32)。

format: uint32

static_pub_key
string

協議公鑰;只供寫入。

minLength: 1

static_pri_key
string

協議私鑰;只供寫入。

minLength: 1

identity_pub_key
string

身份公鑰;只供寫入。

minLength: 1

identity_pri_key
string

身份私鑰;只供寫入。

minLength: 1

hash
string

已棄用嘅兼容欄位;目前值會被忽略而且唔會儲存,建議省略。

peer_kem_public
string

對端 KEM 公鑰;只供寫入。

auth_hex_data
string

目前嘅十六進制認證資料;只供寫入。

authhexdata
string

已棄用嘅舊版十六進制認證資料欄位;只供寫入。

pq_handshake_mode
string

WhatsApp Protocol 會話匯入嘅 PQ 握手模式。

use_xxkem_handshake
boolean

WhatsApp Protocol 會話匯入係咪使用 XXKEM 握手。

如何理解結果

先讀取授權結果,再檢查 runtime_status。匯入與建立連線是不同階段。

回應 200 OK

{
  "request_id": "<REQUEST_ID>",
  "data": {
    "account_id": "acc_example",
    "status": "authorized"
  }
}

回應內容

account_id
string

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

status
string

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

回應

200

200 OK

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

400

請求錯誤

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

401

未授權

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

409

衝突

目前操作同現有嘅渠道帳號或者資源衝突。

500

伺服器錯誤

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

502

上游閘道錯誤

渠道轉接器或者上游渠道未能完成呢個操作。

失敗後如何處理

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

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