Dear community,
I'm having trouble connecting to my companies Jira server using a powershell script and the Invoke-WebRequest commandlet.
I'm using the following script. Note that I'm getting the same error with any valid URI to this Jira server. While the same user can access all these URI's through a webbrowser just fine.
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$baseUrl = "https://MyDomain.atlassian.net"
$jql = "%22Epic Link%22 = SD-2"
$user = 'USER@MyDomain.com'
$pass = 'TheCorrectPassword'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$authHeader = @{
Authorization = $basicAuthValue
}
Invoke-WebRequest -uri $($baseUrl + "/rest/api/latest/search?jql=$jql") -Headers $authHeader -UseBasicParsing -ErrorAction Stop -Verbose
Output from powershell:
Invoke-WebRequest : The remote server returned an error: (401) Unauthorized.
At
\Work\JiraAccess2.ps1:22 char:1
+ Invoke-WebRequest -uri $($baseUrl + "/rest/api/latest/search?jql=$jql ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Could there be a setting on the Jira Server that prevents this user from connecting via "Invoke-WebRequest"? Or is something wrong with my script?
Edit: I'm using the cloud version.