Skip to main content

更新 Git 仓库凭据

更新 Git 仓库资源的 authorization_token。只能更新凭据;url、mount_path、checkout 不可修改。

前提

已完成 Endpoint 与鉴权配置,详见API 总览与认证。会话中已挂载 Git 仓库资源。

接口

POST /sessions/{session_id}/resources/{resource_id}

路径参数

session_id string(必选) 会话 ID,格式 sesn_<ULID>。 resource_id string(必选) Git 仓库资源 ID,格式 sesrsc_<ULID>。

请求体

authorization_token string(必选) 新的访问令牌或密码,不能为空字符串。公开仓库可在创建会话时省略凭据;该接口只用于替换已有令牌。
接口只接受 authorization_token。携带 url、mount_path、checkout 等其他字段会返回 400 invalid_parameter。

请求示例

curl
curl -X POST "$AGENTSTUDIO_URL/sessions/sesn_xxx/resources/sesrsc_xxx" \
  -H "Authorization: Bearer $DASHSCOPE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"authorization_token": "glpat-xxxxxxxxxxxxxxxxxxxx"}'

响应字段

id string 资源 ID,格式 sesrsc_<ULID>。 type string 固定为 git_repository。 url string Git 仓库的 HTTPS 地址,不含凭据。 mount_path string 仓库在会话沙箱中的实际挂载路径。 checkout object / null 创建时指定的检出目标,包含 type 与 name(分支)或 sha(提交);省略时为 null。 created_at / updated_at string 资源创建与最近更新时间,ISO 8601。更新凭据后 updated_at 会变化。 request_id string 本次请求的唯一标识。

响应示例

{
  "id": "sesrsc_zzz",
  "type": "git_repository",
  "url": "https://gitlab.com/group/project",
  "mount_path": "/workspace/project",
  "checkout": {"type": "branch", "name": "main"},
  "created_at": "2026-11-28T02:00:55Z",
  "updated_at": "2026-11-28T02:05:57Z",
  "request_id": "xxx"
}

错误码

状态码错误码说明
400invalid_parameterauthorization_token 为空或格式不合法,返回 Invalid authorization_token
400invalid_parameter携带了不可更新字段,返回 Only authorization_token can be updated
404not_found会话或资源不存在
401InvalidApiKeyAPI Key 无效