Hi Team,
I used branch restriction API and created the branch restrictions and then for merge settings I couldn't find the API. Is this available ?
Hey Karthikraj!
Welcome to the Bitbucket Cloud community!
The merge restriction option is included within the same /2.0/repositories API endpoint that you have been using and can be passed as a JSON argument.
For example, if I was to restrict merges for the master branch to only the admin user group - the JSON argument would look like this:
{"branch_match_kind":"glob","pattern":"master","kind":"restrict_merges","groups":[{"slug":"admin"}]}
Hope this helps.
Cheers!
- Ben (Bitbucket Cloud Support)
Hi @Ben ,
Thanks for the reply.
my requirement is, in merge settings how to define the Merge checks & Merge Conditions through API?
Thanks & Regards.
Karthikraj M
Hey Karthikraj,
Just letting you know firstly that I have edited your comment to censor out your workspaceID/reposlug as this is a public forum.
May I ask if you are using AppPassword to authenticate? If you are not already doing so, please follow our guide below for configuring an AppPassword:https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/
I have been able to successfully execute the cURL command with JSON that you have listed above on my own repository, please ensure the format is correct and then attempt to execute:
curl -X POST \ --url 'https://api.bitbucket.org/2.0/repositories/{workspaceID}/{reposlug}/branch-restrictions?=' \ --user {username}:{AppPassword} \ --header 'Content-Type: application/json' \ --data '{"kind": "restrict_merges","branch_match_kind": "glob","pattern":"develop", "groups":[ { "slug":"administrators","full_slug": "{workspaceID}:administrators", "name": "Administrators","default_permission": "admin", "account_privilege": "admin" } ]}'
NOTE: You will need to replace {workspaceID}, {reposlug}, {username}, {AppPassword} with actual values without the curly braces
Please try this and let me know how it goes.
Hello @Ben ,
for cURL its working for me too. But, I try to use it in python its shows bad request error. How to define the "groups" in python code ?
the same JSON format should work right?
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.bitbucket.org/2.0/repositories/******/******/branch-restrictions
Thanks & Regards,
It looks like you're new here. Sign in or register to get started.