Unable to create ticket via JiraPS - Invoke-JiraMethod: Issue Does Not Exist
Asked by James Underdown:

Hi,

After a recent upgrade to our development environment, I can no longer create tickets via powershell using JiraPS.

I'm still able within our production environment fine, however when I attempt to create the ticket via "New-JiraIssue", I get an error: "Invoke-JiraMethod: Issue Does Not Exist"

However the issue does exist under the project...

I don't think it's permissions as I can query and retrieve data using the Get-JiraIssue query command with no issue.

Any ideas/ suggestions would be appreciated.

Thanks

James


Answers:
author: Dahc
body: I ran into this, it appears to be related to Jira changing the API in version 9. See the open issue below on the JiraPS github:

<https://github.com/AtlassianPS/JiraPS/issues/461>

I stumbled upon this from search, so figured I'd post this to help others.

Edit: Looks like Jira 8.4 introduced this change, so even if you used Invoke-RestMethod some code change will be required:  
<https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/#creating-an-issue-examples>

For anyone arriving here via google:

```
$pair = "${username}:${password}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$headers = @{ Authorization = "Basic $base64" }

$body = @{
fields = @{
project = @{
key = "ProjectKeyHere"
}
issuetype = @{
name = "Task" 
}
summary = "Test Issue via API"
}
}
# Convert the body to JSON format
$body = $body | ConvertTo-Json

Invoke-RestMethod -uri "https://ServerURLHere/rest/api/2/issue" -Method Post -Headers $headers -ContentType "application/json" -Body $body
```

You can also modify the JiraPS file as shown here:  
<https://github.com/spicy/JiraPS/commit/fc2632c1f21b3867667197ec2c8e77b266e60e69>


author: David Bakkers
body: Hello [@James Underdown](/t5/user/viewprofilepage/user-id/5022514)

This is the risk you take with using third party libraries.

Switch to using PowerShell's native *Invoke-RestMethod*. It does mean a bit more coding work on your part, but it always works.

comments: author: Rodolfo So
body: [@David Bakkers](/t5/user/viewprofilepage/user-id/4107683) have you figured this issue? Can you share you code on how to create issue. Thanks


author: Dahc
body: [@Rodolfo So](/t5/user/viewprofilepage/user-id/1952827) I ended up having to use invoke-restmethod, I updated my post above with a code example.


author: Rodolfo So
body: [@Dahc](/t5/user/viewprofilepage/user-id/5138226)

So it mean's you don't use the JIRAPS powershell for this? Right now, I'm having issue using the JiraPS when creating Jira ticket via CSV.

<br />

PS E:\\scripts\> Import-CSV "C:\\Users\\test\\Downloads\\backup\\imporcsv.csv" \| Foreach { New-JiraIssue -Project $_.project  
-Summary $_.summary -Description $_.description }

cmdlet New-JiraIssue at command pipeline position 1  
Supply values for the following parameters:  
IssueType: Story  
Invoke-JiraMethod : Issue Does Not Exist  
At C:\\Program Files\\WindowsPowerShell\\Modules\\JiraPS\\2.14.6\\JiraPS.psm1:2012 char:19  
+ $result = Invoke-JiraMethod @parameter  
+ \~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~  
+ CategoryInfo : InvalidResult: (:) \[Invoke-JiraMethod\], RuntimeException  
+ FullyQualifiedErrorId : InvalidResponse.Status404,Invoke-JiraMethod


author: Dahc
body: [@Rodolfo So](/t5/user/viewprofilepage/user-id/1952827) That's correct, not using JiraPS for this. This is because the developer essentially went MIA it seems... Despite multiple people reporting issues, no changes have been made to JiraPS for what appears to be years.

If you want to use JIRA PS, you'll have to fix the code yourself, as mentioned on this issue report on the Jira PS github: <https://github.com/AtlassianPS/JiraPS/issues/461>

Below is the fix from that issue post that seemed to work for them, but I haven't tried it yet. I saw this after I decided to just use Invoke-RestMethod.   
<https://github.com/spicy/JiraPS/commit/fc2632c1f21b3867667197ec2c8e77b266e60e69>


Tags: confluence-server

server