Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
  • Community
  • Q&A
  • Jira
  • Questions
  • Exception thrown invoking listener [com.pyxis.greenhopper.jira.listeners.CacheEvictionListener]

Invoke-WebRequest API error 401 (Unauthorized)

Christian Thurow
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 28, 2020

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 D:\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.

1 answer

1 accepted

1 vote
Answer accepted
crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 7, 2015

JIRA Agile has a cross-version compatibility layer so that it can "bridge" a common internal abstraction of several services to the correct linkage in different versions, conditionally take advantage of services as they appear, and so on.  The BridgeServiceLocator is the class that helps it figure out which version of a service to use, find it, and use it.  It should be initialized automatically as part of JIRA Agile starting up, and when JIRA Agile goes away or gets upgraded, the old one is explicitly cleared out.

The error message you are seeing means one of two things has happened.  Either:

  1. JIRA Agile did not come up properly and the BridgeServiceLocator for some reason was never initialized; or,
  2. More likely, you have upgraded JIRA Agile, but for some reason bits and pieces of the old version of the plugin did not successfully unregister themselves even though the old BridgeServiceLocator successfully shut itself down, and those leftover bits are still trying to respond to issue events.  In the course of doing so they are trying to talk to the bridge service, and since it's gone you get the error message you reported.

Neither situation is a good one.  I would recommend restarting to see if it clears the situation up, and you might consider reporting this in a support case along with your log files to see if the reason for the failure can be identified in them.

 

 

 

Geoffrey Laparra
Contributor
July 7, 2015

Thank you Chris,

I'm gonna raise this issue at Agile plugin staff.

Edit : Actually it got fixed by it-self by rebooting the server. Thanks again.

Suggest an answer

Log in or Sign up to answer