Obsolete Protected branches API documentation


I’ve recently been tasked with the automatic merging and deleting of a release branch that is protected during its lifespan and when I was trying to work with the documentation for protected branches API, it seems that the instructions are not entirely correct.

At least from what I experienced the documentation specifically mentions that the levels of access should be specified by allowed_to_push / allowed_to_merge / allowed_to_unprotect (see here). However when i use the API call with parameters named like that, the API returns a 400: Bad request.

I have checked the protected branches of our project in API and those parameters are actually called push_access_levels / merge_access_levels / unprotect_access_levels and when I try to call the API with these parameters it works.

Now I’m not sure whether to report this or I do not have all the info but is there some other explanation for why the “official docs approach” does not work?


PS: Also in the docs there does not seem to be an example on how to set multiple users for various access types.

Hi @JanMelicharik maybe this is a silly question, but are you using a personal access token with full read/write repository and API permissions?

Also, would it be possible for you to post the API request you are making? Maybe as a call to curl?

These are Premium only as documented by the Premium next to the header.

Yes, the license we are using is Premium so we have access to those features.

Hello, I am using a personal access token of our service account and it has all the needed permissions.

I have managed to solve the issue and in the end it actually worked as specified in the docs. However it gave me a bit of a headache as there is no example on how to protect a branch and set a user and a group as allowed to push and merge.

I think that this issue is solved and it was my misunderstanding. However i would appriciate more examples in the docs.

@JanMelicharik glad you got it working! If you’ve found a gap in the docs, maybe it’s worth raising an issue for it?

Sure, will do!

Edit: Protected branches API - missing examples (#327471) · Issues · GitLab.org / GitLab · GitLab