Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add branch permission using API with branch name and prevent all changes category?

Ron Bob
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 27, 2018

I saw the documentation we can surely do it but an example would be useful for better understanding. 

API- /rest/branch-permissions/2.0/projects/{projectKey}/repos/{repositorySlug}/restrictions

Correct me if I am wrong with the selection of API call. 

I want to give set of users in JSON format and restrict permission for all others except those in that JSON. I am not sure what should be my JSON schema.  The same way we do it in the UI using Prevent all changes, except by:

1 answer

0 votes
Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 17, 2018

Hi @Ron Bob,

 

The documentation for branch permissions can be found here and if you find the section that says "Example request representations" you will find an example json request to create a branch permission.

The example givein in the documentation is:

{
    "type": "read-only",
    "matcher": {
        "id": "refs/tags/**",
        "displayId": "refs/tags/**",
        "type": {
            "id": "PATTERN",
            "name": "Pattern"
        },
        "active": true
    },
    "users": [
        "bman",
        "tstark",
        "hulk"
    ],
    "groups": [
        "bitbucket-users"
    ],
    "accessKeys": [
        1,
        2,
        3
    ]
}

 

To answer some of your specific questions:

  • In order to 'prevent all changes' you need to set the "type" field to "read-only"
  • To add the 'except by' you need to add users to the "user" field

Hope that helps! Let me know if you need more details.

Yash Bagarka September 6, 2019

Is there any version dependency for using bitbucket server api 2.0 ?

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 8, 2019

Bitbucket Server does not have a 2.0 REST API. But the Bitbucket Cloud documentation can be found here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/branch-restrictions

Baskara Reddy
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 30, 2019

Thanks for answering this. May I know how to remove the restrictions. For eg. disable Prevent all changes.

Александр Тимочкин
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 15, 2019

Could you help me with the same problem?

I had try to use POST by curl to restrict branch permission:

curl --insecure -X POST -H "Authorization: Basic <Base64 hash string>" -H "Content-Type: application/json" -d @@request.json https://somedomain.com/rest/branch-permissions/2.0/projects/MYPRJ/repos/myrepo/restriction

@request.json

{
"type": "read-only",
"matcher": {
"id": "timochkin/release-lock",
"displayId": "timochkin/release-lock",
"type": {
"id": "BRANCH",
"name": "Branch"
},
"active": true
},
"users": [
"atimochkin"
],
"accessKeys": [
1,
2,
3
]
}

and 

HTTP/1.1 200 Connection established

HTTP/1.1 401
Date: Mon, 16 Dec 2019 06:37:48 GMT
Server: Apache
Strict-Transport-Security: max-age=63072000; includeSubdomains; preload
X-AREQUESTID: @257UFSx97x28529719x0
X-ASEN: SEN-2976722
X-AUSERID: 1246
X-AUSERNAME: atimochkin
Cache-Control: no-cache, no-transform
Vary: X-AUSERNAME,Accept-Encoding
Content-Type: application/json;charset=UTF-8
X-Content-Type-Options: nosniff
WWW-Authenticate: OAuth realm="https%3A%2F%2Fsomedomain.com"
Transfer-Encoding: chunked

{"errors":[{"context":null,"message":"You are not permitted to access this resource","exceptionName":"com.atlassian.bitbucket.AuthorisationException"}]}

 

In myrepo, account have Admin permission, what i do wrong?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events