Hello,
i´m trying to access the Bamboo REST API from Powershell. I want to automate some configurations. When i send the Request with a tool like Bruno or Postman i will receive an correct answer. When using the exact same Request from Powershell (From within VSCode or native PowerShell cmd window) i always get an error "System.Net.WebException: Der Remoteserver hat einen Fehler zurückgegeben: (401) Nicht autorisiert."
I tried to use Invoke-WebRequest and/or Invoke-RestMethod. I encoded the Token in UTF-8, used EscapeDataString, [Net.SecurityProtocolType]::Tls12, Token in Single-Quote or Double-Quote and so on. I´m not able to get this working from Powershell. Is there any advice where to search for any clue?
Here is my Powershell Code:
$token = "<MyToken>" # Access Token from Bamboo Profile
$bambooheaders = {
Authorization = "Bearer $token"
"Content-Type"="application/json"
}
$url = 'http://<MyURL>/rest/api/latest/deploy/project/forPlan?planKey=PDCS-ZWZ'
try {
$Response = Invoke-WebRequest -Uri $url -Headers $bambooheaders -Method Get
Write-Host $Response
} catch {
Write-Host $_.Exception -ForegroundColor Red;
}
Any help is much appreciated, since this is very frustrating.