How to configure branching model with REST API in Bitbucket Data Center?
Asked by Lucky:

Dear Community,

I want to configure my Bitbucket Data Center (Atlassian Bitbucket v8.9.12) repository Workflow \> Branches configuration via REST API.

Sadly, I could only find the REST API documentation for Bitbucket Cloud here [The Bitbucket Cloud REST API (atlassian.com)](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-branching-model/#api-group-branching-model) to configure the branching model.

But it doesn't seem to be available in the Bitbucket Data Center version. Or at least I could not find it in the REST API documentation [The Bitbucket Data Center REST API (atlassian.com)](https://developer.atlassian.com/server/bitbucket/rest/v819/intro/#about).

Thanks for a hint.

Best Regards,

Daniel


Answers:
author: Charlie Misonne
body: Hi Daniel and welcome to the Atlassian Community!

I was looking for this a while ago and I found the answer in [this comment](https://jira.atlassian.com/browse/BSERV-5411?focusedId=2385714&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-2385714) on a feature request.

There is an endpoint but is not official. It has been working for years though...

PUT \<bitbucket-url\>/rest/branch-utils/1.0/projects/{projectKey}/repos/{repositorySlug}/branchmodel/configuration

```
{    "development":{        "refId":"refs/heads/develop",        "useDefault":false    },    "types":[        {            "id":"BUGFIX",            "displayName":"Bugfix",            "enabled":true,            "prefix":"bugfix/"        },        {            "id":"FEATURE",            "displayName":"Feature",            "enabled":true,            "prefix":"feature/"        },        {            "id":"HOTFIX",            "displayName":"Hotfix",            "enabled":false,            "prefix":"hotfix/"        },        {            "id":"RELEASE",            "displayName":"Release",            "enabled":true,            "prefix":"release/"        }    ]}
```

Use GET on the same endpoint to view the current branching model of the repo.

I hope this helps!

comments: author: Lucky
body: [@Charlie Misonne](/t5/user/viewprofilepage/user-id/502263) Thanks for the helpful response. Do you maybe know if the other settings under branches Automatic merging, Automatic branch merging behavior and Branch deletion on merge are also configurable via the API?![2024-06-07_15h18_38.png](https://community.atlassian.com/t5/image/serverpage/image-id/328617i9927F4E9ABFAA83E/image-size/large?v=v2&px=999 "2024-06-07_15h18_38.png")

Update: Found this for automatic merging [\[BSERV-4894\] Display auto-merge status using REST API. - Create and track feature requests for Atlassian products.](https://jira.atlassian.com/browse/BSERV-4894) -\> Solved

Still looking for branch-deletion-on-merge but should work via the same endpoint I guess --\> But what's the key which must be used?

```
/rest/branch-utils/1.0/projects/{PROJECT_KEY}/repos/{REPO_SLUG}/<whats the key here?>/enabled
```

UPDATE 2: Found it here [Bitbucket REST API to set 'Branch deletion on merge' - DevOps Stack Exchange](https://devops.stackexchange.com/questions/15081/bitbucket-rest-api-to-set-branch-deletion-on-merge)

It's /rest/branch-utils/latest/projects/{project_key}/delete-after-merge and to set it to ON sent a POST request with {"enabled": true}


author: Charlie Misonne
body: Hi!

You got everything you needed now? :-)


Tags: api

bitbucket-data-center

branching

data-center

rest

rest-api