API 參考

帳號

建立帳號

建立渠道帳號。auth_mode 必填且僅可為 qrcode、code 或 session。當 provider 與 auth_mode 組合需要電話號碼時(例如 WhatsApp + auth_mode=code),必須透過 provider_data.phone 提供;該值會保存並於後續認證動作重用。 餘額模式直接建號,無須先取得報價;201 表示建號與扣款已提交,授權前仍須核對 billing.state。同工作區建號進行中會回傳 409 wallet_account_creation_in_progress。Idempotency-Key 可選;逾時應先核對,只有沿用原鍵重試才可避免重複購買。

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

支援渠道

all

呼叫前準備

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

使用目標工作區的 API Key。餘額模式帳號按 30 天以 USD 計費;錢包餘額與儲值請在 Dashboard 查看。

請求參數

請求標頭

X-Api-Key
string必填

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

Content-Type
string必填

傳送 JSON 請求內容時請使用 application/json。

Idempotency-Key
string

餘額建號可選帶單一 Idempotency-Key;未知結果重試請沿用原鍵。不帶時,前一筆完成後再次請求會新建帳號。

請求內容

name
string

可讀的帳號名稱。

provider
string必填

客戶可用的渠道識別字:telegram、whatsapp、whatsapp-protocol、line、twitter、zalo 或 tiktok。

enum: telegram, whatsapp, line, twitter, zalo, tiktok, whatsapp-protocol, x, x_client, twitter_client

region
string必填

用於分配的渠道區域。請透過 列出渠道區域 選擇 allocatable: true 的區域。

minLength: 1

status
string

帳號業務狀態,例如 active 或 inactive。

runtime_status
string

渠道支援透過帳號設定變更時,所要求的執行階段狀態。

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

auth_mode
string必填

建立帳號時必填;僅可為 qrcode、code 或 session。

enum: qrcode, code, session

capabilities[]
string[]

帳號能力。PATCH 時省略表示保留,傳 [] 表示清空,null 無效。

metadata
object

平台側中繼資料。PATCH 時省略表示保留,傳 {} 表示清空,null 無效。

provider_account_ref
string

渠道側帳號識別字,通常在授權完成後寫入。

provider_data
object

渠道設定。PATCH 時省略表示保留,{} 清空且不補充預設憑證,null 無效。TikTok provider_data.enable_comment 僅接受 Boolean,預設 false;字串、數字、null 回傳 400 invalid_request。線上修改需 reconnect,start 成功不代表設定已套用;關閉不撤回已排隊事件。Telegram 的 code、qrcode、session 均可省略 api_id 與 api_hash;自訂憑證須為同一應用程式的成對字串。建立時未指定自訂憑證、非空設定替換時缺省憑證欄位,均使用平台預設值;所需預設設定不可用時請求失敗。平台預設憑證變更不會替換既有帳號憑證。請勿記錄金鑰。

proxy
object

此帳號可選的對外 proxy 設定。

如何理解結果

餘額模式直接建號,無須先取得報價;201 表示建號與扣款已提交,授權前仍須核對 billing.state。同工作區建號進行中會回傳 409 wallet_account_creation_in_progress。Idempotency-Key 可選;逾時應先核對,只有沿用原鍵重試才可避免重複購買。

回應 201 · PREPAID_QUOTA

{
  "request_id": "<REQUEST_ID>",
  "data": {
    "id": "acc_example",
    "name": "Telegram Production",
    "provider": "telegram",
    "region": "<REGION>",
    "status": "active",
    "runtime_status": "stopped",
    "auth_mode": "qrcode",
    "capabilities": [
      "send_message",
      "receive_message"
    ]
  }
}

回應 201 · ACCOUNT_WALLET_30D

{
  "request_id": "<REQUEST_ID>",
  "data": {
    "id": "acc_example",
    "name": "Messaging account",
    "provider": "telegram",
    "region": "<REGION>",
    "status": "active",
    "runtime_status": "stopped",
    "auth_mode": "qrcode",
    "capabilities": [
      "send_message",
      "receive_message"
    ],
    "billing": {
      "period_start_at": "2026-10-19T00:00:00Z",
      "period_end_at": "2026-11-18T00:00:00Z",
      "amount_minor": 1000,
      "currency": "USD",
      "operation_id": "op_example",
      "state": "ACTIVE"
    }
  }
}

回應內容

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, 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。

capabilities[]
string[]

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

metadata
object

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

provider_account_ref
string

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

proxy
object

帳號綁定的對外 proxy 設定,未設定時省略。

回應

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 排查;它不是冪等鍵或任務識別碼。

auth_mode_phone_required · 20019 · 400

此授權方式要求建立帳號時填寫 provider_data.phone。

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

示意 JSON;message 隨實際原因變化 · 400 · 20019
{
  "request_id": "req_example",
  "error": {
    "code": "auth_mode_phone_required",
    "numeric_code": "20019",
    "message": "Phone number is required for this auth mode"
  }
}
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"
  }
}
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"
  }
}
wallet_invalid_request · 20021 · 400

請檢查餘額建號參數及可選的 Idempotency-Key 請求標頭。

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

示意 JSON;message 隨實際原因變化 · 400 · 20021
{
  "request_id": "req_example",
  "error": {
    "code": "wallet_invalid_request",
    "numeric_code": "20021",
    "message": "Invalid wallet account request"
  }
}
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_allocation_busy · 20011 · 409

帳號正在分配,請稍後重試。

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

示意 JSON;message 隨實際原因變化 · 409 · 20011
{
  "request_id": "req_example",
  "error": {
    "code": "account_allocation_busy",
    "numeric_code": "20011",
    "message": "Allocation is busy in the current region; please retry later"
  }
}
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"
  }
}
no_allocatable_server · 20013 · 409

此區域暫無可分配資源,請查詢其他可分配區域。

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

示意 JSON;message 隨實際原因變化 · 409 · 20013
{
  "request_id": "req_example",
  "error": {
    "code": "no_allocatable_server",
    "numeric_code": "20013",
    "message": "No allocatable server in the current region"
  }
}
wallet_account_creation_in_progress · 20030 · 409

目前工作區已有餘額帳號正在建立,請等待完成後再試。

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

示意 JSON;message 隨實際原因變化 · 409 · 20030
{
  "request_id": "req_example",
  "error": {
    "code": "wallet_account_creation_in_progress",
    "numeric_code": "20030",
    "message": "Account creation is in progress; please wait"
  }
}
wallet_idempotency_conflict · 20024 · 409

冪等鍵已綁定其他業務參數,請先核對原操作結果,避免重複建號。

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

示意 JSON;message 隨實際原因變化 · 409 · 20024
{
  "request_id": "req_example",
  "error": {
    "code": "wallet_idempotency_conflict",
    "numeric_code": "20024",
    "message": "Idempotency key was used for a different request"
  }
}
wallet_insufficient_funds · 20023 · 409

錢包餘額不足,擁有者可儲值後確認原請求。

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

示意 JSON;message 隨實際原因變化 · 409 · 20023
{
  "request_id": "req_example",
  "error": {
    "code": "wallet_insufficient_funds",
    "numeric_code": "20023",
    "message": "Insufficient wallet balance"
  }
}
wallet_workspace_disabled · 20022 · 409

新餘額消費已關閉,不代表既有帳號操作已取消。

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

示意 JSON;message 隨實際原因變化 · 409 · 20022
{
  "request_id": "req_example",
  "error": {
    "code": "wallet_workspace_disabled",
    "numeric_code": "20022",
    "message": "New wallet purchases are disabled"
  }
}
workspace_account_quota_exceeded · 20014 · 409

工作區訊息帳號額度已用滿,請檢查用量與額度。

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

示意 JSON;message 隨實際原因變化 · 409 · 20014
{
  "request_id": "req_example",
  "error": {
    "code": "workspace_account_quota_exceeded",
    "numeric_code": "20014",
    "message": "Workspace account quota exceeded"
  }
}
create_account_failed · 20002 · 500

建立帳號:資源建立失敗或無法確認建立結果。

處理與重試: 再次建立前先列出或查詢既有資源,確認上次建立是否已生效。修正根本原因並保留 request_id,不要自動建立重複資源。

示意 JSON;message 隨實際原因變化 · 500 · 20002
{
  "request_id": "req_example",
  "error": {
    "code": "create_account_failed",
    "numeric_code": "20002",
    "message": "Failed to create account"
  }
}
allocation_service_unavailable · 20012 · 503

帳號分配服務暫時無法使用,請稍後重試。

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

示意 JSON;message 隨實際原因變化 · 503 · 20012
{
  "request_id": "req_example",
  "error": {
    "code": "allocation_service_unavailable",
    "numeric_code": "20012",
    "message": "Allocation service is temporarily unavailable"
  }
}
wallet_unavailable · 20028 · 503

錢包資料或設定暫時無法使用;寫入失敗可能結果未知,請核對原操作。

處理與重試: 先讀取資源目前狀態,確認上一次變更結果,再決定是否重試。保留 request_id;結果未知時不要自動重複寫入。

示意 JSON;message 隨實際原因變化 · 503 · 20028
{
  "request_id": "req_example",
  "error": {
    "code": "wallet_unavailable",
    "numeric_code": "20028",
    "message": "Wallet service is unavailable"
  }
}