Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create a ticket with attachment New-JiraIssue #336

Open
mirrorgleam opened this issue Feb 6, 2019 · 3 comments · May be fixed by #419
Open

Unable to create a ticket with attachment New-JiraIssue #336

mirrorgleam opened this issue Feb 6, 2019 · 3 comments · May be fixed by #419

Comments

@mirrorgleam
Copy link
Contributor

mirrorgleam commented Feb 6, 2019

Description

I'm trying to create a new JIRA issue with a required field of attachment. No matter how I format it I've been unable to get this to work. The attachment is a required field to create the ticket according to the Get-JiraIssueCreateMetadata output but not when creating a JIRA ticket through the web page. When creating a JIRA ticket manually in the web application "Attachment" will have a red star next to it like any other required field but if you don't add anything it doesn't throw an error and the ticket is created.

There isn't any issue with adding an attachment after the ticket has been created with Add-JiraIssueAttachment but as the attachment is a required field for the tickets I'm trying to create I was hoping to be able to add them as I create the ticket.

The output from Get-JiraIssueCreateMetadata:

Id              : attachment
Name            : Attachment
Schema          : @{type=array; items=attachment; system=attachment}
HasDefaultValue : False
Required        : True
Operations      : 

Here are a few of the things I've tried and the errors that haunt my working hours.

$parameters = @{
    Project = "TIKT"
    IssueType = "Ticket"
    Summary = "This is a ticket that was created with the JIRA PowerShell API"
    Description = "Ticket created with JiraPS"
    Reporter = "MyName"

    Fields = @{
        Assignee = "TheirName"
        Attachment = @{ attachment = @( "Path\to\file.txt" )}
        Attachment = @( "Path\to\file.txt" )
        Attachment = "Path\to\file.txt"

    }
}

I didn't try them all at the same time but it was easier to put them in here together.

error: 
Invoke-JiraMethod : 
attachment                                
----------                                
Field does not support update 'attachment'
At C:\Program Files (x86)\WindowsPowerShell\Modules\JiraPS\2.9.0\JiraPS.psm1:3603 char:27
+             if ($result = Invoke-JiraMethod @parameter) {
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidResult: (:) [Invoke-JiraMethod], RuntimeException
    + FullyQualifiedErrorId : InvalidResponse.Status400,Invoke-JiraMethod

If I intentionally misspell the field attachment, for error testing purposes, then I get:
New-JiraIssue : Unable to identify field [Attment] from -Fields hashtable. Use Get-JiraField for more information.

If I run New-JiraIssue without the "attachment" field I get the following error:

New-JiraIssue : Jira's metadata for project [TIKT] and issue type [Ticket] specifies that a field is required that 
was not provided (name=[Attachment], id=[attachment]). Use Get-JiraIssueCreateMetadata for more information.

Then I attempted to run it with the "Attachment filed empty such as:
Attachment = ""
and
Attachment = @()
I still get the "Field does not support update 'attachment'" error

I'm able to create tickets using the python JIRA https://pypi.org/project/jira/ by not including the attachment field. If I do include the attachment field I get the same error:
Field does not support update 'attachment'

If there is a way to bypass the "Attachment" fields check that would be good too.

Perhaps I'm just missing something simple.
Please help

@lipkau
Copy link
Member

lipkau commented Feb 9, 2019

Hey.

That command does not have logic for uploading attachments.
I will try to reproduce it and see how the functionality can be added

@mirrorgleam
Copy link
Contributor Author

Thanks for getting back to me.

It would be nice to have that feature or be able to bypass the required (but not really required) field.
In the mean time I've setup my script to use Invoke-RestMethod to perform the POST method directly to the JIRA server which will create the tickets then I use Add-JiraIssueAttachment within the same foreach loop to attach the files directly after they are created.

When I'm using the Invoke-RestMethod to create the tickets without the attachment field there is no error. I'm thinking the error might be due to a check performed before the POST method is carried out.
Perhaps there is a comparison in the New-JiraIssue function that checks to ensure that required fields are all accounted for before attempting to create the ticket and if they're not then it throws an error before attempting to create the ticket?

@lipkau
Copy link
Member

lipkau commented Feb 21, 2019

Perhaps there is a comparison in the New-JiraIssue function that checks to ensure that required fields are all accounted for before attempting to create the ticket and if they're not then it throws an error before attempting to create the ticket?

Yes. it uses Get-JiraIssueCreateMetadata.
This behavior will only change on v3

@GradyD GradyD linked a pull request Jun 11, 2020 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants