跳转到内容

API 身份验证与权限范围

所有调用都发送到 https://api.click2reply.com/v1/…,请求和响应均为 JSON,并带有 Authorization: Bearer <token> 请求头。组织由令牌决定,绝不取自路径或请求体。POST /v1/oauth/token、/v1/oauth/revoke 和 /v1/oauth/introspect 是例外:它们遵循 RFC 6749,也接受表单格式的请求体,并以 { "error", "error_description" } 格式返回错误。

令牌前缀用途
个人访问令牌c2r_pat_供您自己的脚本使用,以您的身份操作。在设置 > API 和 Webhook 中创建。
机器人令牌c2r_bot_供以机器人客服(而非真人)身份操作的脚本使用。
OAuth 访问令牌c2r_oat_供其他组织安装的应用使用;有效期 60 分钟。
OAuth 刷新令牌c2r_ort_用于换取新的访问令牌;有效期 60 天。

快速入门逐步介绍了每种令牌的获取方式。要查看某个令牌能做什么,请用它调用 GET /v1/oauth/info。要让令牌失效,请在设置中将其撤销;OAuth 令牌也可以通过调用 POST /v1/oauth/revoke 撤销。

令牌实际持有的,是授予它的权限范围中其客服角色仍然允许的那部分,因此令牌能做的事绝不会超过它所代表的人员或机器人。请只授予代码所需的权限范围。

权限范围允许的操作
chats.accessRead and answer the chats of the groups the agent belongs to.
chats.allRead and answer every chat, in every group.
archives.readSearch and read archived chats.
archives.writeChange archived chats.
customers.readRead customer profiles.
customers.writeUpdate customer profiles.
customers.banBan customers.
traffic.readSee live website traffic.
campaigns.manageManage greetings, campaigns and goals.
canned.manageManage canned responses.
tags.manageManage tags.
reports.readRead reports.
team.readRead agents, bots, groups and their status.
team.manageInvite, change and suspend agents; manage groups.
settings.manageChange routing, widget and chat settings.
channels.manageConnect and change messaging channels.
ai.manageChange the AI model settings.
developers.manageManage webhooks, apps and bot tokens.
data.exportExport chats, customers and reports.

账单、角色、您自己的令牌、OAuth 应用注册以及组织本身,只能在已登录的会话中更改,绝不能通过 API 令牌更改。

API 调用从不计量,也不收费。限制只是为了防止单个客户端挤占其他客户端的资源:每个令牌每分钟 600 个请求,每个组织每分钟 3000 个请求(Free 套餐为 120 个)。超出限制时,API 会返回 429,并附带以秒为单位的 retry-after 响应头;每个响应都带有 ratelimit-policy。

所有错误的格式都相同,HTTP 状态码由 code 决定:

{ "error": { "code": "validation", "message": "event.text: Too small", "details": {} } }
code状态码
validation400
authentication401
authorization403
not_found404
conflict409
chat_inactive409
agent_unavailable409
entity_too_large413
idempotency_key_reused422
unsupported_version426
too_many_requests429
plan_limit402
internal500
not_implemented501
service_unavailable503

message 是面向开发者的英文说明,可能会有变化;请根据 code 编写分支逻辑。每个响应都带有 X-Request-Id 响应头:就某个调用联系我们时,请提供该值。

列表接口接受 ?limit=(默认 25,最大 100),并返回 { "items": [...], "next_page_token": "..." }。传入 ?page_token= 即可读取下一页;该令牌已包含首次调用的筛选条件,因此只需单独发送它。next_page_token 为 null 时表示已是最后一页。

所有写操作(POST、PUT、PATCH、DELETE)都接受 Idempotency-Key 请求头:由您自行生成的唯一值,例如 UUID,长度为 1 到 255 个可打印 ASCII 字符。例如在超时之后,用同一个键再次发送同一请求,在 24 小时内您会收到第一次的响应,并带有 Idempotent-Replayed: true 标记,而不会再写入一次。

  • 同一个键用于不同的请求体或其他路由时,会被以 422 idempotency_key_reused 拒绝。
  • 某个键的第一个请求仍在处理时,第二个请求会收到 409 conflict,其 details.reason 为 idempotency_in_flight:请稍后重试。
  • 只保存成功(2xx)的响应,因此失败的请求在重试时会重新执行。
  • 发放凭据(令牌、密钥、恢复码、签名链接)的响应从不保存,因此重试这类请求(例如 POST /v1/tokens)会重新执行。
  • 不带令牌的请求(例如登录)以及请求体超过 1 MB 的请求(例如上传)会忽略该键。
  • 键按凭据区分:同一个键随其他令牌、会话、客服或客户发送时,视为另一个独立的键。

聊天事件的 custom_id 对该事件起同样的作用,且没有时间限制。

API 参考列出了所有路由及各自所需的权限范围。