AtlassianPS / JiraPS

PowerShell module to interact with Atlassian JIRA
https://AtlassianPS.org/module/JiraPS
MIT License
322 stars 131 forks source link

New-JiraSession failed to get an answer from the server #364

Closed ABricka closed 4 years ago

ABricka commented 4 years ago

Description

Hello, I got an issue when trying to create a New-JiraSession. For sure, we're using JiraCloud. Using the verbose parameter I see : VERBOSE: [Invoke-JiraMethod] Failed to get an answer from the server

I also tried to use the headers with a created API Token but with no results.

Your Environment

The 3 tries I done with different issues troubleshooting found.

The first one, classic :

$gcred = Get-Credential -Message "Please log in with your JIRA credentials"
Set-JiraConfigServer 'https://XXXX.atlassian.net:8080' -Verbose
New-JiraSession -Credential $gcred -Verbose

Output

VERBOSE: [Set-JiraConfigServer] Function Started
VERBOSE: [Set-JiraConfigServer] Complete
VERBOSE: [New-JiraSession] Function Started
VERBOSE: [Get-JiraConfigServer] Function Started
VERBOSE: [Get-JiraConfigServer] Complete
VERBOSE: [Invoke-JiraMethod] Function Started
VERBOSE: [ConvertTo-GetParameter] Making HTTP get parameter string out of a hashtable
VERBOSE:
Name                    Value
----                    ----
maxResults              25

VERBOSE: [Invoke-JiraMethod] Get https://XXXX.atlassian.net:8080/rest/api/2/mypermissions?maxResults=25
VERBOSE: [Invoke-JiraMethod] Failed to get an answer from the server
VERBOSE: [Test-ServerResponse] Checking response headers for authentication errors
VERBOSE: [Invoke-JiraMethod] No Web result object aws returned from. This is unusual !
VERBOSE: [Invoke-JiraMethod] Function ended
VERBOSE: [New-JiraSession] Complete

The second try :

$password = ConvertTo-SecureString 'APIToken' -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ('mymail@mail.com',$password)
New-JiraSession -Credential $creds -Verbose

Output

VERBOSE: [New-JiraSession] Function Started
VERBOSE: [Get-JiraConfigServer] Function Started
VERBOSE: [Get-JiraConfigServer] Complete
VERBOSE: [Invoke-JiraMethod] Function Started
VERBOSE: [ConvertTo-GetParameter] Making HTTP get parameter string out of a hashtable
VERBOSE:
Name                    Value
----                    ----
maxResults              25

VERBOSE: [Invoke-JiraMethod] Get https://XXXX.atlassian.net:8080/rest/api/2/mypermissions?maxResults=25
VERBOSE: [Invoke-JiraMethod] Failed to get an answer from the server
VERBOSE: [Test-ServerResponse] Checking response headers for authentication errors
VERBOSE: [Invoke-JiraMethod] No Web result object aws returned from. This is unusual !
VERBOSE: [Invoke-JiraMethod] Function ended
VERBOSE: [New-JiraSession] Complete

The third try :

function ConvertTo-Base64($string) {
   $bytes = [System.Text.Encoding]::UTF8.GetBytes($string)
   $encoded = [System.Convert]::ToBase64String($bytes)
   return $encoded
}
function Get-HttpBasicHeader($Headers = @{}) {
   $credentials = Get-Credential -Message "Please log in with your GSuite credentials (mail address and API token)"
   [string]$username = $credentials.UserName
   [string]$password = $credentials.GetNetworkCredential().Password
   $b64 = ConvertTo-Base64 "$($username):$($password)"
   $Headers["Authorization"] = "Basic $b64"
   $Headers["X-Atlassian-Token"] = "nocheck"
   return $Headers
}
$header = Get-HttpBasicHeader
Get-JiraIssue SR-2317 -Verbose

Output

VERBOSE: [Get-JiraIssue] Function Started
VERBOSE: [Get-JiraConfigServer] Function Started
VERBOSE: [Get-JiraConfigServer] Complete
VERBOSE: [Get-JiraIssue] Processing [SR-2317]
VERBOSE: [Invoke-JiraMethod] Function Started
VERBOSE: [ConvertTo-GetParameter] Making HTTP get parameter string out of a hashtable
VERBOSE:
Name                    Value
----                    ----
expand                  transitions
maxResults              25
fields                  *all

VERBOSE: [Get-JiraSession] Function Started
VERBOSE: [Get-JiraSession] Complete
VERBOSE: [Invoke-JiraMethod] Get https://XXXX.atlassian.net:8080/rest/api/latest/issue/SR-2317?expand=transitions&maxResults=25&fields=*all
VERBOSE: [Invoke-JiraMethod] Failed to get an answer from the server
VERBOSE: [Test-ServerResponse] Checking response headers for authentication errors
VERBOSE: [Invoke-JiraMethod] No Web result object aws returned from. This is unusual !
VERBOSE: [Invoke-JiraMethod] Function ended
VERBOSE: [Get-JiraIssue] Complete
ABricka commented 4 years ago

Hi guys, I'm already in trouble and don't work anymore. Have you any kind of solution or viewing some mistakes by me ?

lipkau commented 4 years ago

Hi @ABricka

are you sure about the :8080 in that url? never saw that on atlassian.net before.

what do you get in the browser (in which you have previously logged in to your jira server) when you open https://XXXX.atlassian.net:8080/rest/api/latest/issue/SR-2317?expand=transitions&maxResults=25&fields=*all ?

ABricka commented 4 years ago

Hi @lipkau , Thank you for your reply. You're on a good point with that :8080, by the browser i have a blank page after a long loading, without :8080 the informations inside the browser appears, i can identify my comments inside all the text. I don't really know why i'm using this :8080 for jira, i use it for another tool but that's all.

And yes it works well now, thanks a lot 👍