How to allow Workspace/Project Access Token to have write permissions in a (protected) branch
Asked by Sumanta Chakraborty:

I believe <https://jira.atlassian.com/browse/BCLOUD-20121> is very similar to the issue I am hitting.

I have a workspace access token, and I also am protecting the release branch.

The workspace access token can create tags, but not a release branch. How do I give that permission to the token?

The workaround in that ticket is to use OAuth... and I did not want my jenkins/TeamCity based CI CD pipeline script to have to go through that hassle. Is there another way? How do we create protected branches from non-atlassian CI/CD?

To be clear, I am trying to create a branch.

<br />

PS build\> invoke-restmethod -Method 'POST' -uri "<https://api.bitbucket.org/2.0/repositories/$workspace/$slug/refs/branches>" -Headers $headers -Body $body  
invoke-restmethod : {"type": "error", "error": {"message": "You are not allowed to create a branch that matches the pattern \\"release/\*\\".", "code":  
"BRANCH_PERMISSION_VIOLATED", "data": {"key": "BRANCH_PERMISSION_VIOLATED"}}, "data": {"key": "BRANCH_PERMISSION_VIOLATED"}}  
At line:1 char:1  
+ invoke-restmethod -Method 'POST' -uri "<https://api.bitbucket.org/2.0/> ...  
+ \~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~  
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) \[Invoke-RestMethod\], WebException  
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand  
PS build\>

PS build\> $headers

Name Value  
---- -----  
Authorization Bearer XXXXXX..  
Content-Type application/json  
Accept application/json

PS build\> $body  
{  
"name": "release/XXXX",  
"target": {  
"hash": "HEAD"  
}  
}  
PS build\>


Answers:
author: Patrik S
body: Hello [@Sumanta Chakraborty](/t5/user/viewprofilepage/user-id/5190045) ,

Thank you for reaching out to Atlassian Community!

I've noticed that you have also opened an internal ticket with us, as you have an active Bitbucket subscription, and one of our support engineers is already working with you on that ticket.

I would just like to share here as well, in case others are interested in the same feature, that currently Workspace/Project/Repository Access tokens (WATs, PATs and RATs) are not available to be added in the branch permissions. We have a feature request open to implement this functionality, which can be accessed using the following link :

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

I would suggest you to add your vote there, since this helps both developers and product managers to understand the interest. Also, make sure you add yourself as a watcher in case you want to receive first-hand updates from that ticket. Please note that all features are implemented with [this policy](https://confluence.atlassian.com/support/implementation-of-new-features-policy-201294576.html) in mind.

The current workaround is using basic auth with an [App Password](https://support.atlassian.com/bitbucket-cloud/docs/app-passwords/) to authenticate the request.

Thank you, [@Sumanta Chakraborty](/t5/user/viewprofilepage/user-id/5190045) !

Patrik S


author: Sumanta Chakraborty
body: Looking for guidance...

comments: author: Sumanta Chakraborty
body: Basic auth of user kind of works - but I get Rate limited continuously.


Tags: bitbucket-cloud

cloud

migration