Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Jira REST API returning 401 Unauthorized

Austin Luu May 24, 2019

Hello,

I recently lost the ability to login to the Jira REST API using powershell, constantly getting 401 unauthorized errors. My account has admin privileges and I know I'm using the correct password. Anyone might know what I'm doing wrong?

 

Invoke-RestMethod -UseBasicParsing -Method Post -Uri "https://15sof1.atlassian.net/rest/auth/1/session" -SessionVariable session -Body (@{username = $username; password = $password} | convertTo-Json -Compress) -ContentType 'application/json'

Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:1 char:1
+ Invoke-RestMethod -UseBasicParsing -Method Post -Uri "https://15sof1. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

 

Thanks!

3 answers

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 26, 2019

Hi all,

I was working with Austin on a related post and I think we found the solution.

Atlassian Cloud recently deprecated support for TLS 1.0 and 1.1 protocols.  This will force all clients to support TLS 1.2 in order to connect. Deprecating TLSv1 and TLSv1.1 for Atlassian Cloud Products has more details.

While the planned effective date in that page was December 1, 2018, you can see in the recent Jira Cloud blog updates in https://confluence.atlassian.com/cloud/blog/2019/07/atlassian-cloud-changes-jul-1-to-jul-8-2019

... after consultation internally and with customers, we have allowed a silent/soft grace period of 6 months to allow customers additional time to update the necessary tools and systems. This grace period has now expired. 

In my search I came across this post:

https://www.codyhosterman.com/2016/06/force-the-invoke-restmethod-powershell-cmdlet-to-use-tls-1-2/

The issue, as I understand it, is that PowerShell by default uses TLS 1.0 for web requests, which will not work in our case. So this needs to be changed. Thankfully, this is an easy change. Just add the following line to your scripts:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Which means that we would need to make sure powershell is using the TLS v1.2 protocol when trying to connect to an Atlassian Cloud address, or else it won't be able to connect.

Cheers,

Andy

0 votes
Austin Luu May 28, 2019

Still facing the same problem with API token, any other suggestions?

0 votes
Ignacio Pulgar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 24, 2019

Create an API token and replace your password with it:

https://confluence.atlassian.com/cloud/api-tokens-938839638.html

Austin Luu May 24, 2019

I'm still getting the same error with the API token:

Invoke-RestMethod -UseBasicParsing -Method Post -Uri "https://15sof1.atlassian.net/rest/auth/1/session" -SessionVariable session -Body (@{username = $username; password = $apitoken} | convertTo-Json -Compress) -ContentType 'application/json'

Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:1 char:1
+ Invoke-RestMethod -UseBasicParsing -Method Post -Uri "https://15sof1. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Ignacio Pulgar
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 29, 2019

I tried that approach with Postman only.

Austin Luu May 29, 2019

Any other suggestions?

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events