Where are the settings for allowing rewriting and deleting in Branch permission API response?

Hello,

Looking at the API response for a branch permission (see below), we are not able to find ‘Allow rewriting branch history’ nor ‘Allow deleting this branch’ settings in the response (see this screenshot

for the settings that I’m referring to here.

Are those just not in the API or do I need to look somewhere else?

Below is an example of the response for a test repo branch permission…we can find all the settings except those two mentioned above.

Thanks!

{
“pagelen”: 10,
“values”: [
{
“kind”: “require_passing_builds_to_merge”,
“users”: ,
“links”: {
“self”: {
“href”: 2.0/repositories/ABC/private-repo-test/branch-restrictions/4128570"
}
},
“pattern”: “test”,
“value”: 1,
“groups”: ,
“type”: “branchrestriction”,
“id”: 4128570
},
{
“kind”: “require_approvals_to_merge”,
“users”: ,
“links”: {
“self”: {
“href”: 2.0/repositories/ABC/private-repo-test/branch-restrictions/4128569"
}
},
“pattern”: “test”,
“value”: 1,
“groups”: ,
“type”: “branchrestriction”,
“id”: 4128569
},
{
“kind”: “reset_pullrequest_approvals_on_change”,
“users”: ,
“links”: {
“self”: {
“href”: “2.0/repositories/ABC/private-repo-test/branch-restrictions/4128568”
}
},
“pattern”: “test”,
“value”: null,
“groups”: ,
“type”: “branchrestriction”,
“id”: 4128568
},
{
“kind”: “require_tasks_to_be_completed”,
“users”: ,
“links”: {
“self”: {
“href”: “2.0/repositories/ABC/private-repo-test/branch-restrictions/4128567”
}
},
“pattern”: “test”,
“value”: null,
“groups”: ,
“type”: “branchrestriction”,
“id”: 4128567
},
{
“kind”: “enforce_merge_checks”,
“users”: ,
“links”: {
“self”: {
“href”: “/2.0/repositories/ABC/private-repo-test/branch-restrictions/4128566”
}
},
“pattern”: “test”,
“value”: null,
“groups”: ,
“type”: “branchrestriction”,
“id”: 4128566
},
{
“kind”: “restrict_merges”,
“users”: [
{
“username”: “tc”,
“display_name”: “TC”,
“type”: “user”,
“uuid”: “{760f4849-362f-46e8-a676}”,
“links”: {
“self”: {
“href”: “api.bitbucket.org/2.0/users/tc
},
“html”: {
“href”: “/tc/”
},
“avatar”: {
“href”: “/account/tc/avatar/32/”
}
}
},
{
“username”: “aw”,
“display_name”: “AW”,
“type”: “user”,
“uuid”: “{2dcdcae5-101d-4939-ad3e}”,
“links”: {
“self”: {
“href”: “/2.0/users/aw”
},
“html”: {
“href”: “/aw/”
},
“avatar”: {
“href”: “/account/aq/avatar/32/”
}
}
}
],
“links”: {
“self”: {
“href”: “/2.0/repositories/ABC/private-repo-test/branch-restrictions/4128565”
}
},
“pattern”: “test”,
“value”: null,
“groups”: ,
“type”: “branchrestriction”,
“id”: 4128565
},
{
“kind”: “push”,
“users”: [
{
“username”: “aw”,
“display_name”: “AW”,
“type”: “user”,
“uuid”: “{2dcdcae5-101d-4939-ad3e}”,
“links”: {
“self”: {
“href”: “/2.0/users/aw”
},
“html”: {
“href”: “/aw/”
},
“avatar”: {
“href”: “account/aw/avatar/32/”
}
}
}
],
“links”: {
“self”: {
“href”: “/2.0/repositories/ABC/private-repo-test/branch-restrictions/4128564”
}
},
“pattern”: “test”,
“value”: null,
“groups”: ,
“type”: “branchrestriction”,
“id”: 4128564
}
],
“page”: 1,
“size”: 7
}

Hi David,

Here the API doesn’t translate exactly to the UI. The checkboxes you mention control different “kinds” of branch restrictions.

When you leave them unchecked in the UI, we will create a restriction where 'kind': 'force' and 'kind': 'delete' for “Allow rewriting branch history” and “Allow deleting this branch” respectively. If you check them in the form, we don’t create these branch restrictions.

You can see all the different kinds in the schema documentation here: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/{username}/{repo_slug}/branch-restrictions#post

require_tasks_to_be_completed
require_passing_builds_to_merge
force
require_all_dependencies_merged
push
require_approvals_to_merge
enforce_merge_checks
restrict_merges
reset_pullrequest_approvals_on_change
delete

1 Like

Thank you! We needed to be looking for the absence of these values…of course, why didn’t I think of that! I was looking at the great schema documentation but it didn’t click for me for some reason.

Many thanks for this thoughtful reply.

Rock on,
-Hardwick