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.