0
votes

How to add an attachment using JIRA::REST?

I can able to create the Jira ticket. But I am unable to attach the text file. please help on this matter.

Error message :

 ERROR: @  JIRA::REST Error[415 - Unsupported Media Type]:
 at copy_of_new-jira.pl line 56. 

Perl script

#Mobules of script   
    use JIRA::REST;
    use Data::Dumper;
    use Devel::Trace;
    use JSON; 

    # Iterate on issues
    my $search = $jira->POST('/search', undef, {
        jql        => 'project = xxx AND issuetype = Bug AND status = Unassigned AND created >= -10m',
        startAt    => 0,
        maxResults => 1,
        fields     => [ qw/summary status assignee/ ],
    });

    foreach my $issue (@{$search->{issues}}) {
        print "Found issue $issue->{key}\n";
    }


    # Attach files using an utility method

     my $filename = "/root/perl-script/image.txt"; 
     # Attach files using an utility method
     $jira->attach_files(xxx-56639, ($filename));
1
Have you tried the attach_files method? - choroba
If used attach_files method as getting an error like (Undefined subroutine &Encode::encode_utf8 called at /usr/local/share/perl5/JIRA/REST.pm line 355.) - Nataraj
Try adding use Encode; somewhere near the top of /usr/local/share/perl5/JIRA/REST.pm - choroba
Added encode to pm file. still, the same issue is existing also updated the code according to attach_files - Nataraj
Very unlikely. If Encode is present (and it should, it's core since 5.8), it should work. What version of Perl and Encode do you run? - choroba

1 Answers

0
votes

you should use attach_files to attach files using JIRA::REST:

$jira->attach_files($key,($filename));

Note that you pass an array, which means you can at several files at once.