账号授权
开始验证码认证
使用账号已保存的手机号启动授权。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" } }