What scope to use?


I am trying to creat a pull request via API. I am using Bitbucket app for authentification and I would like to ask you, what scope do I need to allow to be able to create a PR with close_source_branch set to TRUE?

Everytime I am tryign to creat a PR, I get error message:

{“type”: “error”, “error”: {“message”: “You are restricted from closing the source branch.”}}

Thank you for your help!

1 Like

I have the same problem. Does anyone have solution for this? Thanks!

Your app should have pullrequest:write scope to be able to so that.

You will be able to do that from https://bitbucket.org/account/user/{username}/api --> Oauth consumers --> Edit option of consumer --> Permissions at the bottom of the page

Here is a sample request:

curl --location --request POST 'https://api.bitbucket.org/2.0/repositories/<username>/<repo-name>/pullrequests?access_token=<access-token>' \
--header 'Content-Type: application/json' \
--data-raw '{
        "title": "My Title",
        "close_source_branch": true,
        "source": {
            "branch": {
                "name": "test"

I’m using bitbucket cloud, and an app password which has the pullrequest:write permission.
Submitting a pull request with close_source_branch: true was working before.

Then after setting per-branch permissions to:

master: write: nobody, merge via pull request: my account
update-*: write: everybody, merge via pull request: everybody

it stopped working.

It wound up being issue that i didn’t allow deleting of the update-* branch as well in the branch permissions. After fixing that, close_source_branch: true works.