Merge Pull Request via 2.0 REST API
Asked by CT Wu:

Hi All,

I have an access token with all permission, however, I cannot merge a pull request via REST API with this token. The error prompt is as follows.

\> Merging a pull request requires write access to the destination branch

The REST API totally follows the official [documents](https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-pull-request-id-merge-post).

In addition, I have verified my repo's branch restriction which is no any rule.


Answers:
author: Theodora Boudale
body: Hi [@CT Wu](/t5/user/viewprofilepage/user-id/5111884) and welcome to the community!

Could you please provide the following info, so we can better help you?

**1)** Is this a PR between two branches in the same repo? Or is it a PR from a forked repo to the parent of the fork?

**2)** What kind of token are you using?

* Is it a token generated from an OAuth consumer?
* Is it an Access token generated from **Repository settings \> Access tokens** for this repo, on Bitbucket Cloud website?
* Or is it an app password generated for your account from <https://bitbucket.org/account/settings/app-passwords/> ?

Kind regards,  
Theodora

comments: author: CT Wu
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) ,

1. Two branches in the same repo owned by me.

2. Repository settings \> Access tokens for this repo, on Bitbucket Cloud website, plus all permissions are checked.


author: Theodora Boudale
body: Hi [@CT Wu](/t5/user/viewprofilepage/user-id/5111884),

Thank you for the info. There was a bug preventing a merge via API using a repository access token, we had a public bug report about this here:

* <https://jira.atlassian.com/browse/BCLOUD-22353>

The bug was fixed a few hours ago.

Could you please try running the API call again now and let me know if it works?

Kind regards,  
Theodora


author: CT Wu
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) ,

I have verified, and it works.

Thanks.


author: Theodora Boudale
body: That's good to hear, thank you for the update.

Please feel free to reach out if you ever need anything else!

Kind regards,  
Theodora


author: Dhiraj Sittu
body: Hi [@Theodora Boudale](/t5/user/viewprofilepage/user-id/818086) ,

I'm facing the exact same issue.

I'm trying to hit the following curl:

curl --location --request POST '<https://api.bitbucket.org/2.0/repositories/>\<workspace\>/\<repo\>/pullrequests/1493/merge' \\  
--header 'Authorization: Bearer \<access_token\>' \\  
--header 'Accept: application/json' \\  
--header 'Content-Type: application/json' \\  
--data-raw '{  

}'

I have created the access_token from **Repository settings \> Access tokens** for this repo, on Bitbucket Cloud website. All the permissions are checked except **Delete repo**.

I'm getting the following error response:  
{  
"type": "error",  
"error": {  
"message": "newstatus: Merging a pull request requires write access to the destination branch.",  
"fields": {  
"newstatus": \[  
"Merging a pull request requires write access to the destination branch."  
\]  
}  
}  
}  
I've attached the permissions screenshot.![Screenshot 2023-03-01 at 7.52.02 PM.png](https://community.atlassian.com/t5/image/serverpage/image-id/243161iD5C988FCDDC661AE/image-size/large?v=v2&px=999 "Screenshot 2023-03-01 at 7.52.02 PM.png")


author: Theodora Boudale
body: Hi Dhiraj,

I will reply to the other post you created here:

<https://community.atlassian.com/t5/Bitbucket-questions/REST-API-2-0-to-merge-a-Pull-Request-is-throwing-write-access/qaq-p/2286647>

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud