Hello,
I can't seem to make any API calls to Jira using PowerShell, always getting errors below. Can anyone spot what I'm doing wrong?
$user = 'austin.luu91@gmail.com'
$pass = 'apiToken'
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
Invoke-WebRequest -Uri 'https://15sof1.atlassian.net/rest/api/2/search?jql=project = CIT AND issuetype = "JIRA Request" AND (created >= startOfDay(-30d) OR updated >= startOfDay(-30d))' `
-Headers $Headers\
Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel.
At line:1 char:1
+ Invoke-WebRequest -Uri 'https://15sof1.atlassian.net/rest/api/2/searc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Hi Austin,
Sorry to hear that you are having this REST API problem when trying to make requests to an Atlassian Cloud site. I thought perhaps the problem here was in the way the credentials are passed at first, but the more I look at it, that part looks ok, I think.
My concern is to understand if the call you're making is actually using the HTTP verb GET here or not. I don't see any parameter that clearly states that. But since I'm not well versed in powershell, I'm not sure the syntax needed here. I found a related thread in https://community.atlassian.com/t5/Answers-Developer-Questions/JIRA-Create-an-issue-using-Powershell-without-using-curl/qaq-p/556689 that might be helpful here. Granted that user is trying to create issues, which uses the POST verb, and your endpoint needs to use the GET verb, but perhaps that can help to correct this.
Alternatively, looking at this again, it could be the URL / URI that you are calling here that could be the problem. The fact that the URL contains spaces, and mixes the use of single quote ' and double quote " could be a potential problem here in terms of making a valid call. Two different approaches could help troubleshoot this:
project = CIT AND issuetype = "JIRA Request" AND (created >= startOfDay(-30d) OR updated >= startOfDay(-30d))
When that filter is saved in Jira, and you view that filter it will have a 5 digit number like 10100. You can then access that filter with a spaceless URL such as
https://15sof1.atlassian.net/rest/api/2/search?jql=filter=10100
I'd be interested to see if that works. The lack of spaces and quotes here is a good test to see if perhaps those are mucking up the request in an unexpected way or not.https://15sof1.atlassian.net/rest/api/2/issue/SCRUM-123
where SCRUM-123 is the issue key of a single issue that your account has access to view. I'm just interested to see if this call works or if you get a similar error. This call is also using the GET HTTP verb, so if the error is identical, it tends to indicate that maybe we are not using the correct verb to make this call.Please let me know the results.
Cheers,
Andy
Hi Andy,
Thanks for throwing out all those suggestions. I tried all of them but they didn't seem to work, getting the same error.
I've added -Method GET, although the default should be GET.
Punching the following url into a browser worked, so I tried to use this in my query.
https://15sof1.atlassian.net/rest/api/2/issue/OPS-117
I've simplified my query to the following:
$user = 'austin.luu91@gmail.com'
$pass = #API_KEY
$pair = "$($user):$($pass)"
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))
$basicAuthValue = "Basic $encodedCreds"
$Headers = @{
Authorization = $basicAuthValue
}
Invoke-WebRequest -Uri 'https://15sof1.atlassian.net/rest/api/3/OPS-117' -Method GET -Headers $Headers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Austin,
I think I might have found another thing to look at. 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. Searching your error a bit 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
I have run across a few other users recently that have encountered this problem with various clients, such as in:
Try that and let me know if this helps.
Cheers,
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Andy! That seemed to have worked for trying to get issues.
It seems like the API significantly changed recently. Can you point me to instructions of how to take backups and download them? I used to do this, but it seems like these endpoints are no longer valid.
Invoke-WebRequest -Method Post -Uri "https://15sof1.atlassian.net/rest/api/3/session" -Headers $headers -SessionVariable session -ContentType 'application/json'
$InitiateBackup = Invoke-WebRequest -Method Post -Headers @{"Accept"="application/json"} -Uri "https://15sof1.atlassian.net/rest/api/3/backup/export/runbackup" -WebSession $session -ContentType 'application/json' -Body $bodyjson -Verbose | ConvertTo-Json -Compress | Out-Null
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Austin,
Glad to hear that part is working now.
For the backups question, I think it would be best to ask it in a new question. That way others that search on the topic in Community can benefit from the answer more easily than trying to answer it here.
Also, I see that you have asked this original question a few different times on the site and never seem to have found a solution. I would also recommend accepting this answer if it solves the original problem. I can also go back to your past questions and provide an update there on the solution. I think it would help both the other users that tried to help in the past and others that search the topic to share this knowledge.
Thanks
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.