帳號授權
開始驗證碼認證
使用帳號已儲存的電話號碼啟動授權。WhatsApp 從 data.verify_code 讀取配對碼,在手機端輸入,不必提交至 /auth/code。Telegram 將使用者收到的驗證碼提交至 /auth/code,需要二次密碼時再呼叫 /auth/password。awaiting_code 不代表授權成功。
https://api.unifyport.ai/v1/accounts/{account_id}/auth/start支援渠道
呼叫前準備
在伺服器端使用資源所屬工作區的 X-Api-Key,執行範例前替換所有預留位置。
參數從哪裡取得
- account_id
- 從建立或查詢帳號的回應取得 data.id。帳號屬於 X-Api-Key 對應的工作區。 取得帳號
請求參數
請求標頭
X-Api-Key工作區 API Key,工作區會由此標頭解析得到。
Content-Type傳送 JSON 請求內容時請使用 application/json。
路徑參數
account_id用於該 authentication 路由的識別字。
請求內容
此介面接收空 JSON 物件;請依請求範例傳送 {}。
如何理解結果
依本次授權動作讀取 status/auth_status 和實際回傳的 auth_payload。需要使用者操作時依管道指南繼續;authorized 表示授權完成,傳送前仍須檢查 runtime_status。
回應 200 · WhatsApp
{
"request_id": "<REQUEST_ID>",
"data": {
"provider": "whatsapp",
"action": "start_auth",
"status": "awaiting_code",
"auth_status": "awaiting_code",
"verify_code": "ABCD-EFGH"
}
}
回應 200 · Telegram
{
"request_id": "<REQUEST_ID>",
"data": {
"provider": "telegram",
"action": "start_auth",
"status": "awaiting_code",
"auth_status": "awaiting_code",
"auth_payload": {
"type": "code"
}
}
}
回應內容
provider本次授權動作對應的渠道。
enum: telegram, whatsapp, line, twitter, zalo, tiktok, whatsapp-protocol
action請求的授權動作,值為 start_auth。
enum: start_auth
status目前授權狀態;awaiting_code 表示等待使用者操作,authorized 才表示授權完成。
auth_status目前授權步驟的標準狀態,通常與 status 一致。
verify_codeWhatsApp 電話號碼配對碼,直接位於 data 下。讓使用者在手機端輸入,不必提交至 /auth/code;回應不保證提供到期時間。
auth_payloadobject渠道特定的授權提示。Telegram 可回傳 type=code,不包含使用者收到的驗證碼。
auth_payload渠道特定的授權提示。Telegram 可回傳 type=code,不包含使用者收到的驗證碼。
type授權提示類型;Telegram 驗證碼步驟為 code。
回應
200200 · WhatsApp
請求成功,回應內容範例如上。
400請求錯誤
請求內容、路徑或參數無效。
401未授權
X-Api-Key 請求標頭缺少或無效。
403禁止存取
請求已識別,但不允許執行此操作。
404找不到資源
找不到請求的資源;請結合 error.code 和目前操作核對。
409衝突
目前操作與既有的渠道帳號或資源衝突。
500伺服器錯誤
服務遇到了未預期的錯誤。
502上游閘道錯誤
渠道轉接器或上游渠道未能完成此操作。
失敗後如何處理
檢查 HTTP 狀態和 error.code/numeric_code,保留 request_id。依原因修正參數、繼續授權或檢查狀態。重試傳送及寫入前確認上次結果,避免重複操作。 錯誤碼參考
結合目前操作讀取 HTTP 狀態、error.code 和 error.numeric_code。數字碼以字串處理。保留 request_id 排查;它不是冪等鍵或任務識別碼。
- invalid_request · 10000 · 400
檢查 JSON 請求本文與必填欄位。
處理與重試: 按目前操作與渠道條件修正參數後再請求。重複提交相同的無效請求不會解決錯誤。
示意 JSON;message 隨實際原因變化 · 400 · 10000
{ "request_id": "req_example", "error": { "code": "invalid_request", "numeric_code": "10000", "message": "Invalid request parameters" } }- 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" } }- provider_invalid_request · 30001 · 400
檢查管道專屬欄位及格式。
處理與重試: 按目前操作與渠道條件修正參數後再請求。重複提交相同的無效請求不會解決錯誤。
示意 JSON;message 隨實際原因變化 · 400 · 30001
{ "request_id": "req_example", "error": { "code": "provider_invalid_request", "numeric_code": "30001", "message": "Provider rejected the request" } }- unsupported_action · 30005 · 400
無法識別此帳號操作,請使用文件列出的操作。
處理與重試: 選擇文件列為支援的渠道與動作。重複請求不會增加能力或開通內測權限。
示意 JSON;message 隨實際原因變化 · 400 · 30005
{ "request_id": "req_example", "error": { "code": "unsupported_action", "numeric_code": "30005", "message": "Action not supported" } }- 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" } }- account_already_authorized · 20016 · 409
帳號已完成授權,本次動作拒絕重複授權。重新整理授權狀態並沿用已完成結果,不要循環重新授權或取消。
處理與重試: 保留 request_id 與結構化錯誤碼,先排查目前操作,再決定下一步。
示意 JSON;message 隨實際原因變化 · 409 · 20016
{ "request_id": "req_example", "error": { "code": "account_already_authorized", "numeric_code": "20016", "message": "Account is already authorized; re-authentication is not required" } }- account_binding_not_found · 30006 · 409
帳號尚無有效的管道連線綁定,請檢查帳號狀態。
處理與重試: 查詢授權與執行狀態,再按目標狀態和渠道支援選擇重新整理、啟動或重新連線。連線問題本身不證明已登出;執行依賴連線的業務操作前確認 running。
示意 JSON;message 隨實際原因變化 · 409 · 30006
{ "request_id": "req_example", "error": { "code": "account_binding_not_found", "numeric_code": "30006", "message": "Account is not bound to an available server" } }- duplicate_provider_account · 20015 · 409
工作區內已有另一個帳號綁定相同管道身分。
處理與重試: 保留 request_id 與結構化錯誤碼,先排查目前操作,再決定下一步。
示意 JSON;message 隨實際原因變化 · 409 · 20015
{ "request_id": "req_example", "error": { "code": "duplicate_provider_account", "numeric_code": "20015", "message": "A provider account with the same identity already exists in this workspace" } }- provider_account_mismatch · 20017 · 409
請求中的管道身分與帳號綁定不一致。
處理與重試: 保留 request_id 與結構化錯誤碼,先排查目前操作,再決定下一步。
示意 JSON;message 隨實際原因變化 · 409 · 20017
{ "request_id": "req_example", "error": { "code": "provider_account_mismatch", "numeric_code": "20017", "message": "Authenticated provider account does not match the bound account; re-scan with the original account" } }- 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" } }- provider_not_ready · 30014 · 409
此帳號所需的渠道執行個體缺失。這是執行個體可用性問題,不證明授權已過期。
處理與重試: 查詢授權與執行狀態,再按目標狀態和渠道支援選擇重新整理、啟動或重新連線。連線問題本身不證明已登出;執行依賴連線的業務操作前確認 running。
適用渠道: WhatsApp
示意 JSON;message 隨實際原因變化 · 409 · 30014
{ "request_id": "req_example", "error": { "code": "provider_not_ready", "numeric_code": "30014", "message": "Provider instance is missing" } }- provider_not_ready · 30015 · 409
渠道執行程序已停止。啟動前確認這是否為預期狀態;執行狀態停止本身不等於已登出。
處理與重試: 查詢授權與執行狀態,再按目標狀態和渠道支援選擇重新整理、啟動或重新連線。連線問題本身不證明已登出;執行依賴連線的業務操作前確認 running。
適用渠道: WhatsApp
示意 JSON;message 隨實際原因變化 · 409 · 30015
{ "request_id": "req_example", "error": { "code": "provider_not_ready", "numeric_code": "30015", "message": "Provider runtime is stopped" } }- 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" } }- run_auth_action_failed · 30010 · 500
渠道未能完成本次操作。message 可能在「Provider operation failed:」後附帶原始原因;原因文字可變,不是穩定的程式介面。
觸發條件: 適用於渠道未提供更具體失敗分類的情況,保留目前操作的錯誤。
處理與重試: 查詢目前授權流程,檢查是否需要使用者操作。不要僅因本次失敗重新發起授權,也不要向已過期或已結束的工作階段重複提交。
適用渠道: WhatsApp
示意 JSON;message 隨實際原因變化 · 500 · 30010
{ "request_id": "req_example", "error": { "code": "run_auth_action_failed", "numeric_code": "30010", "message": "Provider operation failed" } }- provider_adapter_not_found · 30004 · 502
管道服務暫時無法使用,請檢查狀態或稍後再試;重試寫入操作前先確認上次結果。
處理與重試: 查詢目前授權流程,檢查是否需要使用者操作。不要僅因本次失敗重新發起授權,也不要向已過期或已結束的工作階段重複提交。
示意 JSON;message 隨實際原因變化 · 502 · 30004
{ "request_id": "req_example", "error": { "code": "provider_adapter_not_found", "numeric_code": "30004", "message": "Provider adapter unavailable" } }- provider_unavailable · 30002 · 502
管道服務暫時無法使用,請檢查狀態或稍後再試;重試寫入操作前先確認上次結果。
處理與重試: 查詢目前授權流程,檢查是否需要使用者操作。不要僅因本次失敗重新發起授權,也不要向已過期或已結束的工作階段重複提交。
範例 · 502 · 30002
{ "request_id": "req_example_provider_unavailable", "error": { "code": "provider_unavailable", "numeric_code": "30002", "message": "Provider service unavailable" } }- provider_unavailable · 30010 · 502
渠道未能完成本次操作。message 可能在「Provider operation failed:」後附帶原始原因;原因文字可變,不是穩定的程式介面。
處理與重試: 查詢目前授權流程,檢查是否需要使用者操作。不要僅因本次失敗重新發起授權,也不要向已過期或已結束的工作階段重複提交。
適用渠道: WhatsApp
範例 · 502 · 30010
{ "request_id": "req_example_operation_failed", "error": { "code": "provider_unavailable", "numeric_code": "30010", "message": "Provider operation failed: Example operation could not be completed" } }- provider_unavailable · 30021 · 502
本次操作時 WhatsApp 未建立連線,message 保留原始連線原因。這不證明已登出或授權失效,也不會自動重新連線、重送或修改帳號狀態。
處理與重試: 暫停依賴連線的業務操作。先呼叫 POST /v1/accounts/{account_id}/runtime/refresh,按最新狀態恢復,確認 runtime_status=running 後再請求業務介面。重送前確認上一次寫入結果。
適用渠道: WhatsApp
範例 · 502 · 30021
{ "request_id": "req_example_connection_disconnected", "error": { "code": "provider_unavailable", "numeric_code": "30021", "message": "example operation: websocket not connected" } }