2

For some reason I am unable to update access control on for a protected branch in GitLab. The PATCH request goes through with a status of '200' but the data is not updated. I have tried via Postman, CURL, and Python.

Here is the python code:

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)

The output shows that the access_level was not changed for either 'push_access_levels' or 'merge_access_levels'

{
  "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
}

I followed the exact example from GitLabs API documentation: https://docs.gitlab.com/ee/api/protected_branches.html#example-update-a-push_access_level-record

Eric27710
  • 85
  • 1
  • 6

0 Answers0