Bitbucket API - Merge Settings
Asked by Chris Lugar:

Is it possible via the API to enable/disable and configure the various Merge Checks and Merge Conditions?

In the documentation I see the ability to manage branch restrictions, but not the above features - <https://developer.atlassian.com/cloud/bitbucket/rest/api-group-branch-restrictions/#api-repositories-workspace-repo-slug-branch-restrictions-post>

Is there any way to manage the Merge Checks and Conditions in a batch? I've got a large number of repositories that I need to apply some default settings for and hoping to not have to do it one by one.

Thanks


Answers:
author: Patrik S
body: Hello [@Chris Lugar](/t5/user/viewprofilepage/user-id/2391316) ,

Thank you for reaching out to Atlassian Community!

You can indeed use the branch permissions endpoint to change the configuration of merge checks and conditions as well. This can be achieved by using different values for the **kind**attribute in the body of the request.

Following is an example of API call to add the merge check "No unresolved pull request tasks" to a branch restriction configured to match the glob pattern **development/\***:

```
curl -X POST -H "Content-Type: application/json" -u <username>:<app_password> "https://api.bitbucket.org/2.0/repositories/<workspace>/<repoName>/branch-restrictions" -d '{ "branch_match_kind": "glob","kind": "allow_auto_merge_when_builds_pass","pattern": "development/*" }'
```

You can replace the **kind** attribute with the string that matches the desired merge check. The following options are available to be used as the value of **kind** :

```
require_tasks_to_be_completedallow_auto_merge_when_builds_passrequire_passing_builds_to_mergeforcerequire_all_dependencies_mergedrequire_commits_behindrestrict_mergesenforce_merge_checksreset_pullrequest_changes_requested_on_changerequire_no_changes_requestedsmart_reset_pullrequest_approvalspushrequire_approvals_to_mergerequire_default_reviewer_approvals_to_mergereset_pullrequest_approvals_on_changedelete
```

Please note that only one "**kind** " value can be used in each request. This means that if want to configure multiple merge checks/conditions, you'll have to make multiple requests with each merge check/condition.

Also, to delete/disable a specific merge/check condition, you will first need to get its ID from the [List branch restrictions endpoint](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-branch-restrictions/#api-repositories-workspace-repo-slug-branch-restrictions-get) , and then provide the ID to [Delete a branch restriction rule endpoint](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-branch-restrictions/#api-repositories-workspace-repo-slug-branch-restrictions-id-delete).

Hope that helps! Let me know in case you have any questions.

Thank you, [@Chris Lugar](/t5/user/viewprofilepage/user-id/2391316) !

Patrik S

comments: author: Ulrich Kuhnhardt _IzymesCo_
body: Thanks for sharing [@Patrik S](/t5/user/viewprofilepage/user-id/4603309) The Bitbucket REST API link that [@Chris Lugar](/t5/user/viewprofilepage/user-id/2391316) posted only mentions

"kind describes what will be restricted. Allowed values include: push, force, delete and restrict_merges"

Could you please investigate why the REST API document is incomplete and if that is the case update <https://api.bitbucket.org/swagger.json> and publish the new document.

Thanks, Ulrich


author: Patrik S
body: Hello [@Ulrich Kuhnhardt _IzymesCo_](/t5/user/viewprofilepage/user-id/4011392) ,

I'm already in touch with our engineering team and we have created an internal ticket to update the documentation with all the values available for the **kind**attribute.

Thank you, [@Ulrich Kuhnhardt _IzymesCo_](/t5/user/viewprofilepage/user-id/4011392) :)

Patrik S


Tags: bitbucket-cloud

cloud