API 參考

帳號

列出帳號

列出目前工作區的渠道帳號。帳號的認證狀態透過 Authentication 介面公開。

GEThttps://api.unifyport.ai/v1/accounts

支援渠道

all

呼叫前準備

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

請求參數

請求標頭

X-Api-Key
string必填

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

查詢參數

limit
integer

每頁最多返回的帳號數,範圍為 1 至 100,省略時為 20。無效值或重複傳入 limit 時返回 400 invalid_request(numeric_code=10000);後續分頁可調整此值。

minimum: 1 · maximum: 100

cursor
string

帳號列表的不透明游標。省略或傳入空字串時讀取第一頁;後續分頁原樣回傳上次回應的 data.next_cursor。僅適用於簽發時的 workspace;無效、重複傳入或跨 workspace 使用 cursor 時返回 400 invalid_request(numeric_code=10000)。

請求內容

此介面無需 JSON 請求內容。

如何理解結果

從 data.items 讀取帳號。data.has_more 為 true 時,將 data.next_cursor 原樣作為 cursor 查詢下一頁。帳號授權狀態須另查授權介面。

回應 200 OK

{
  "request_id": "<REQUEST_ID>",
  "data": {
    "items": [
      {
        "id": "acc_example",
        "name": "Telegram Production",
        "provider": "telegram",
        "region": "global",
        "status": "active",
        "runtime_status": "running",
        "auth_mode": "qrcode",
        "capabilities": [
          "send_message",
          "receive_message"
        ],
        "metadata": {
          "env": "production"
        },
        "provider_account_ref": "provider-side-identifier",
        "provider_profile": {
          "id": "778899",
          "phone": "8600000000000",
          "username": "production_bot",
          "display_name": "Production Bot",
          "first_name": "Production",
          "last_name": "Bot",
          "avatar_url": "https://example.com/avatar.jpg",
          "bio": "Customer support"
        }
      }
    ],
    "has_more": false
  }
}

回應內容

provider_profile
object

渠道回報的個人檔案,例如 display_name。帳號認證完成前不會出現。

id
string

渠道側帳號識別字。WhatsApp 回傳 LID;帳號資料同步完成前可能省略。

device_id
integer

僅 WhatsApp 帳號詳情在可確認目前工作階段時提供的選用登入裝置編號;重新授權後可能改變,不作永久裝置識別。

minimum: 0 · maximum: 65535

phone
string

已正規化的帳號電話號碼,不含空格、連字號與開頭加號。

username
string

渠道回報的 username(若有)。

display_name
string

帳號展示名稱;WhatsApp 按 BusinessName 優先、PushName 回退的規則生成。

push_name
string

WhatsApp 目前帳號設定的 PushName;其他渠道未定義此欄位語義。

business_name
string

WhatsApp BusinessName;渠道未回傳時此欄位缺失。

first_name
string

渠道回報的名字(若有)。

last_name
string

渠道回報的姓氏(若有)。

avatar_url
string

渠道回報的帳號頭像 URL(若有)。

bio
string

渠道回報的帳號簡介或狀態文字(若有)。

platform
string

WhatsApp 配對時回報的登入平台識別字。請將它視為不透明字串並相容未知值;其他渠道未定義此欄位語義。此欄位與 device_platform 不同。

billing
object

訊息帳號已付週期,僅餘額帳號存在;不能依錢包餘額推斷已購買。

period_start_at
string

伺服器回傳的已付週期起點。

format: date-time

period_end_at
string

伺服器回傳的已付週期終點。

format: date-time

amount_minor
integer

伺服器不可變金額,單位為 USD 分,須以精確整數處理。

minimum: 1 · format: int64

currency
string

僅 USD。

operation_id
string

來自 billing.operation_id 或刪除回應的公開標識,於原工作區原樣重用。

state
string

計費或操作狀態,不證明帳號已授權、上線或退款已入帳。

enum: ACTIVE, DELETING, DELETED, COMPENSATED, REVIEW

id
string

唯一的帳號識別字(acc_...)。請用於帳號層級的路由。

name
string

可讀的帳號名稱。

provider
string

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

enum: telegram, whatsapp, line, twitter, facebook, zalo, tiktok, whatsapp-protocol

region
string

帳號選擇的預設網路出口地區。

status
string

帳號生命週期狀態,例如 active。

runtime_status
string

標準化的執行階段狀態,為 unknown、starting、running、stopping、stopped、reconnecting、disconnected 或 error 其中之一。

enum: unknown, starting, running, stopping, stopped, reconnecting, disconnected, error

auth_mode
string

帳號使用的認證流程:code、qrcode 或 session。TikTok 支援 qrcode 與 session,但不支援兩種模式原地切換。

capabilities[]
string[]

帳號已啟用的能力,例如 send_message 與 receive_message。

metadata
object

儲存於帳號、面向自有環境的標籤。

provider_account_ref
string

渠道側的識別字,可附加用於將帳號與自有系統關聯對應。

proxy
object

客戶明確設定的代理;不回傳平台預設出口憑證。

has_more
boolean

帳號列表是否還有下一頁。

next_cursor
string

帳號列表下一頁的不透明游標,僅在 has_more=true 時返回;後續分頁以 cursor 原樣傳入,最後一頁省略此欄位。

回應

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 請求本文與必填欄位。

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

示意 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"
  }
}
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"
  }
}
list_accounts_failed · 20000 · 500

列出帳號:服務未能產生有效的查詢結果。

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

示意 JSON;message 隨實際原因變化 · 500 · 20000
{
  "request_id": "req_example",
  "error": {
    "code": "list_accounts_failed",
    "numeric_code": "20000",
    "message": "Failed to list accounts"
  }
}