About branch restrictions
Asked by Hiago Foppa Strach Jager:

I've worked in a shell script to run a job into Rundeck platform, and when it pass by the payload to set the branch restrictions via cUrl -X POST, the rules are not created when i set the groups that are immune to this, but when i dont set them, the rules work's well


Answers:
author: Patrik S
body: Hello [@Hiago Foppa Strach Jager](/t5/user/viewprofilepage/user-id/4662932) ,

Welcome to Atlassian Community!

From my understanding you are are trying to set the branch restriction for your repository using the following API endpoint :

```
POST /2.0/repositories/{workspace}/{repo_slug}/branch-restrictions
```

If that is the case, I was able to successfully create a **push** restriction on my personal repository, applying to branches matching the pattern **development/\*** and with the group named '**contributors**' being except from the restriction, using the example payload below :

```
curl --request POST --user <BBUsername>:<AppPassword> --url https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/branch-restrictions --header 'Accept: application/json' --header 'Content-Type: application/json' --data '{
"kind": "push",
"branch_match_kind": "glob",
"pattern": "development/*",
"groups": [
{
"slug": "contributors"
}
]
}'
```

Would you mind confirming if the payload you are using is similar to the one above ?

Also, from this API endpoint documentation, some conditions must be met in order to use it :

* Groups used in branch restrictions must have write or admin access to the repository
* `users` and `groups` are lists of users and groups that are except from the restriction. They can only be configured in `push` and `restrict_merges` restrictions kinds.
* Adding new users or groups to an existing restriction should be done via `PUT`.

For more details about this particular endpoint, you can refer to the following link:

* <https://developer.atlassian.com/cloud/bitbucket/rest/api-group-branch-restrictions/#api-repositories-workspace-repo-slug-branch-restrictions-post>

Hope that helps to address your question! Let me know if you need further assistance :)

Thank you, [@Hiago Foppa Strach Jager](/t5/user/viewprofilepage/user-id/4662932) !

Best regards,

Patrik S

comments: author: Hiago Foppa Strach Jager
body: Hi [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) , thanks for answering me, i've been successful in creating the branch-restrictions, with this payload: ![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/173296iE937B317650D1D61/image-size/large?v=v2&px=999 "image.png")

Now the problem that i have its about adding new default-reviewers, when i try the curl below it worked for my personal repository:

![image.png](https://community.atlassian.com/t5/image/serverpage/image-id/173297iE34D42D0B474A340/image-size/large?v=v2&px=999 "image.png")

but, when this query is given to RunDeck platform, my supervisor receives a error 401, or dont receive any response, ive trying to figure the reason, if you know something that can be causing this. Thanks for all your support \<3


author: Patrik S
body: Hello [@Hiago Foppa Strach Jager](/t5/user/viewprofilepage/user-id/4662932) ,

Great to hear that you were able to successfully create the branch-restrictions with the API call.

In regards to your latest questions, 401/403 HTTP error codes either means that you are not using valid credentials or do not have the required permissions for that action.

That being said, I'd check with your supervisor the following points :

* Is your supervisor using an **AppPassword** to authenticate with Bitbucket ? If the answer is no, he/she can refer to the following documentation on how to set up one :
  * <https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/>
* If your supervisor is already using an AppPassword, could you please ensure it have the right permissions ? For the API call to **default reviewers** endpoint, both the App Password and the account that owns the AppPassword must have **Repository:Admin** permission.

In case the above doesn't work, could you please share with us the full output of when your supervisor is executing the API call?

Let us know how it goes, and if you have any other questions.

Thanks, [@Hiago Foppa Strach Jager](/t5/user/viewprofilepage/user-id/4662932)

Kind regards,

Patrik S


Tags: bitbucket-cloud

cloud

script