Setting repository connections using REST API

I'm try to add read permissions to forked repositories so that team members can access each others commits.

I have a powershell script that looks roughly like this:


[Parameter(Mandatory=${true})][string]$gitUser = "jdoe",
[Parameter(Mandatory=${false})][string]$gitPrj = "DEMO"

$headers = @{}
$headers.Add('Authorization','Basic 123abc456def')

$repos = @("repo1","repo2","repo3","repo4","repo5")

foreach ($repo in $repos) {
   $uri = "http://$gitHost/rest/api/1.0/projects/~$gitUser/repos/$repo/permissions/groups?permission=REPO_READ&name=R_STAS_$gitPrj_dev"
   $response = Invoke-RestMethod -Uri $uri -Headers $headers -Method "POST"


This works nicely for the first two repos, but the third (and subsequent) API call fail with a timeout:

System.Net.WebException: The operation has timed out.
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()

The order of the repositories doesn't matter so breaking the script up in chunks that does 2 repos and then calling all the two-repo scripts does in fact work.


Stash support is unable to help sad

Has anybody tried something similar?





1 answer


Adaptavist just released a new Add-on to the Marketplace called ScriptRunner for Stash. I'm replying here since I can't answer your question directly but this Add-on may be an easier workaround for updating Stash repository permissions in bulk.

There is a section in the documentation that outlines how to get started with a permission script provided:

Also, there is functionality that can set default permissions for each new repository that gets created in the future and is covered in the documentation here:

Finally, there is a video available that goes through this on our Youtube channel:

I hope that helps, if so - could you please mark this as an answer?



Mark McCormack

Adaptavist ScriptRunner for Stash - Product Owner.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 06, 2018 in Bitbucket

Do you use Bitbucket Cloud and Jira Cloud? If so, let us know!

Hi Community, I'm Julia and I'm on the Jira Software Cloud marketing team!  We're looking for companies or teams using Bitbucket Cloud and Jira Software Cloud. If your team fits the t...

87 views 3 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you