Forums

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

Troubling Creating Bitbucket Cloud Branch Permissions via API

Angelo Loria
Contributor
May 22, 2019

I'm attempting to script branch permissions for repos in Bitbucket Cloud, as there's no way to apply permissions per Project/Team. I'm having trouble with the JSON payload. There is an example request here, but the example request is confusing and frustratingly can't be copied/pasted, even. I am making the call with Powershell, and intended to have the JSON payload defined in it's own JSON file that I'll pass into the call.

 https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/branch-restrictions

 

For example, I'm not sure what href or name to input here-

links: {

self: {

href: string (uri)

name: string

}

}

I've tried a bunch of different ways, but always receive a 400 error with no actual message indicating what isn't correct. The call itself is making it (I can GET branch permissions that I've set up in the UI), so I'm assuming my JSON just isn't formatted correctly or is missing something. Does anyone have any examples of JSON they are using to successfully set branch permissions? 

2 answers

1 accepted

0 votes
Answer accepted
Daniil Penkin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 20, 2019

Hi @Angelo Loria

The API docs are indeed confusing, I'm not sure why links element is even mentioned in the request. Here're are some examples of valid payload for create branch restriction endpoint:

{
"branch_match_kind": "glob",
"kind": "restrict_merges",
"pattern": "master",
"users": [
"dpenkin"
]
}
{
"branch_match_kind": "branching_model",
"kind": "push",
"branch_type": "production",
"users": [
"dpenkin"
]
}
{
"pattern": "bar",
"kind": "push"
}
{
"pattern": "foo",
"kind": "require_approvals_to_merge",
"value": 3
}

Hope this helps.

Cheers,
Daniil

Hannes Schmid
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!
August 29, 2019

Hi,

I had the same struggle with understanding what the group attribute should look like.

Posting the solution now, since it might help others:

{
"branch_match_kind": "branching_model",
"branch_type": "development",
"kind": "restrict_merges",
"groups": [
{
"slug": "my-group-slug",
"owner": {"username": "group-owner-acoount-slug"}
}
]

}

 

 

Is it possible to include such examples in the official docs too?

Like # people like this
AbhishekRsv April 26, 2021

Can you provide a complete branch permission configuration in json payload like Merge Checks , Merge Condition selection and selecting multiple users along with a APIs

0 votes
AbhishekRsv April 26, 2021

Can you provide a complete branch permission configuration in json payload like Merge Checks , Merge Condition selection and selecting multiple users along with a APIs

Suggest an answer

Log in or Sign up to answer