Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

API call to enable repository access to a new user

Edited

I had created a project level token with admin access and was trying to use Bitbucket API call (as recommended in "The Bitbucket Server REST API (atlassian.com)"). Here was my API call:

curl --request PUT --url "https://xxxx:8443/rest/api/latest/projects/PROJ/repos/test/permissions/users?name={new_user_name}&permission={REPO_READ}"


However, getting below error while running this API:

{"errors":[{"context":null,"message":"You are not permitted to access this resource","exceptionName":"com.atlassian.bitbucket.AuthorisationException"}]}


I had also tried to run from a Powershell script:

$token = <<mytoken>>

$permissionsData = @{
permission = $permission
}

$permissionsJson = $permissionsData | ConvertTo-Json

$headers= @{
Authorization = "Bearer $token"

}


$url="https://xxxx:8443/rest/api/latest/projects/PROJ/repos/test/permissions/users?name={new_user_name}&permission={REPO_READ}"
$response = Invoke-WebRequest -Uri $url -Method PUT -Headers $headers -Body $permissionsJson -contentType "application/json"

However, this PowerShell script gives below output:

Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
At line:xx char:13
+ $response = Invoke-WebRequest -Uri $url -Method PUT -Headers $headers ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Looking for your help to address this.

1 answer

0 votes
Navpreet Ahuja
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Nov 06, 2023

Hi

The `curl` request looks fine but it's missing the authorization header, hence the error.

You can pass the HTTP access token in that curl request

e.g.

```

curl --request PUT -H "Authorization: Bearer {HTTP-access-token}" --url "https://xxxx:8443/rest/api/latest/projects/PROJ/repos/test/permissions/users?name={new_user_name}&permission={REPO_READ}"

```

 

If it still fails, make sure the token is not expired or has the correct permissions

Thanks for your inputs. It's working now. 

I have also tried it from PowerShell using below which is working:

$url = "https://xxxxx:8443/rest/api/latest/projects/PROJ/repos/REPO/permissions/users?name={username}&permission={permission}"
$response = Invoke-WebRequest -Uri $url -Method PUT -Headers $headers -Body $permissionsJson -contentType "application/json"

Like Navpreet Ahuja likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events