It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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": [
    "groups": [
    "accessKeys": [


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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder :  #!/bin/bash source "$(dirname "$0")/" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

4,032 views 4 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you