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

渠道上报的用户名(如有)。

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"
  }
}