You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.