You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab API PATCH更新protected_branch权限返回200但数据未变更

GitLab受保护分支权限更新失败问题

无法更新GitLab中受保护分支的访问控制权限。调用API发送PATCH请求时返回状态码200,但实际权限数据并未更新。已尝试通过Postman、CURL及Python三种方式操作。

Python代码示例

import requests
import json

url = "http://<gitlab-url>/api/v4/projects/8/protected_branches/main?private_token=<api-token"

payload = json.dumps({
  "allowed_to_push": [
    {
      "id": 8,
      "access_level": 30
    }
  ],
  "allowed_to_merge": [
    {
      "id": 8,
      "access_level": 0
    }
  ]
})
headers = {
  'Content-Type': 'application/json',
  'Cookie': 'preferred_language=en'
}

response = requests.request("PATCH", url, headers=headers, data=payload)

print(response.text)

API返回结果

返回结果显示push_access_levels和merge_access_levels的access_level均未发生变化:

{
  "id": 8,
  "name": "main",
  "push_access_levels": [
    {
      "id": 8,
      "access_level": 40,
      "access_level_description": "Maintainers"
    }
  ],
  "merge_access_levels": [
    {
      "id": 8,
      "access_level": 40,
      "access_level_description": "Maintainers"
    }
  ],
  "allow_force_push": false
}

已严格遵循GitLab API文档中「更新推送访问权限记录」的示例操作。

内容的提问来源于stack exchange,提问作者Eric27710

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 23:07:06