Skip to content

查询当前凭证的组织、权限和可用操作 ​

返回当前凭证所属的组织、scope、档位(access_level)和各操作是否可用。可用 operations 指定最多 20 个操作名过滤;available 只表示凭证和配置允许尝试,不保证分区或资源权限。

请求 ​

text
POST https://open.cli.im/api/v2/rpc/auth/getContext
项目要求
最低权限只读,见权限档位
需要的 scope不需要,有效凭证即可
组织 Key可以调用

请求参数 ​

请求体为 JSON。

字段类型必填说明
detailstring否返回内容的详略:summary(默认)或 full。本接口始终返回完整的 capabilities 列表,这个参数不改变返回内容。可选值:summary、full。默认 "summary"
operationsstring[]否只返回这些操作的可用情况,传操作名(即 operationId),最多 20 个,不能重复;不传返回全部。至少 1 项。最多 20 项

请求示例 ​

示例里的 ID、幂等键等换成实际值。

bash
curl -sS -X POST 'https://open.cli.im/api/v2/rpc/auth/getContext' \
  -H "Authorization: Bearer ${CAOLIAO_API_KEY}" \
  -H 'Content-Type: application/json' \
  -d '{
  "operations": [
    "qrcodes_create",
    "qrcodes_delete"
  ]
}'

响应 ​

成功时 HTTP 状态码为 200,顶层 code 为 0,结果在 data 里。失败时的返回见错误码与调用额度和业务错误码。

字段类型一定返回说明
data.organizationobject是凭证所属组织
data.organization.idstring是组织 ID
data.organization.namestring是组织名称
data.auth_typestring是oauth 表示个人 API Key 或 OAuth 令牌;api_key 表示组织 Key。可选值:oauth、api_key
data.user_idstring是凭证对应的成员 ID;组织 Key 为 null
data.authorization_modestring是oauth_scoped 按 scope 授权;organization_full 组织 Key,不检查 scope。可选值:oauth_scoped、organization_full
data.client_idstring是凭证的客户端标识;个人 API Key 为 pk: 开头
data.effective_scopesstring[]是当前凭证实际生效的 scope
data.capabilitiesobject[]是各操作是否可用
data.capabilities[].operationstring是操作名,即各接口的 operationId
data.capabilities[].required_scopestring是所需 scope;不需要 scope 时为 null
data.capabilities[].required_scopesstring[]否需要多个 scope 时列出全部
data.capabilities[].availableboolean是当前凭证和配置是否允许调用。不代表分区、资源权限或额度一定满足
data.capabilities[].unavailable_reasonstring是不可用的原因:scope_denied 缺少 scope;not_configured_or_disabled 未开放;org_content_access_disabled 组织的最高权限不允许;unknown_operation 未知操作。可用时为 null
data.capabilities[].resource_check_requiredboolean是调用时是否还要检查分区或资源权限
data.access_levelstring是组织设置的最高权限档位。可选值:read、write、full
data.content_accessobject是由 access_level 得出的修改、删除范围
data.content_access.editstring是ai_created 只能修改通过接口创建的内容;all 可修改全部内容。可选值:ai_created、all
data.content_access.deletestring是none 不能删除;all 可以删除。可选值:none、all
data.capability_scopestring是capabilities 覆盖的范围,固定为 registered_mcp_operations
data.notesstring[]是对结果的补充说明

响应示例 ​

json
{
  "code": 0,
  "message": "ok",
  "data": {
    "organization": {
      "id": "94910252",
      "name": "示例企业"
    },
    "auth_type": "oauth",
    "user_id": "831988",
    "authorization_mode": "oauth_scoped",
    "client_id": "pk:1024",
    "effective_scopes": [
      "assets.write",
      "qrcodes.read",
      "qrcodes.write",
      "records.read",
      "templates.read",
      "templates.write"
    ],
    "capabilities": [
      {
        "operation": "qrcodes_create",
        "required_scope": "qrcodes.write",
        "available": true,
        "unavailable_reason": null,
        "resource_check_required": true
      },
      {
        "operation": "qrcodes_delete",
        "required_scope": "qrcodes.write",
        "available": false,
        "unavailable_reason": "scope_denied",
        "resource_check_required": true,
        "required_scopes": [
          "qrcodes.write",
          "content.delete"
        ]
      }
    ],
    "access_level": "write",
    "content_access": {
      "edit": "ai_created",
      "delete": "none"
    },
    "capability_scope": "registered_mcp_operations",
    "notes": [
      "available 表示凭证和配置允许尝试,不保证分区或资源权限。"
    ]
  }
}

本页由 openapi.json 生成。全部接口见接口清单。