Hi All,
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:
Hi @Dhiraj Sittu and welcome to the community!
If the screenshot you shared is from the PR's destination branch, then the reason you are getting this error message is that merge of PRs is restricted only to certain users.
Repository access tokens are not associated with the user that generated them or with any other user. They also cannot be added to a branch restriction, so you won't be able to merge this PR with a Repository access token (RAT) as long as this branch restriction exists.
Merging a PR via API with a RAT is possible as long as PR merging is not restricted to certain users and everyone is allowed to merge.
If you would like to keep the branch restriction for PR merging, then the only way to merge the PR with an API call is by using the authentication details of a user who has permission to merge the PR:
curl -u BB_Username:App_Password -X POST 'https://api.bitbucket.org/2.0/repositories/<workspace-id>/<repo>/pullrequests/<pr_id>/merge'
where
BB_Username is the username of a Bitbucket Cloud user who has permission to merge PRs to the destination branch
App_Password is an app password for that user's account, that has Pull requests: Write permissions
We have a feature request for allowing admins to add a Repository access token to branch restrictions:
I would suggest adding your vote (by selecting the Vote for this issue link) and commenting on the feature request to give it more weight and further express your interest. You can also add yourself as a watcher (by selecting the Start watching this issue link) if you'd like to get notified via email on updates. Implementation of new features is done as per our policy here and any updates will be posted in the feature request.
Please feel free to let me know if you have any questions.
Kind regards,
Theodora
Hello Dhiraj, Welcome to the community!
I hope I can help: The request authorization header can be
If you try to send the same curl request with `curl -u "<username:accessToken>" .....` you should get the Auth header for free.
Good luck and let me know how you go!
Best, Ulrich
// Izymes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.