I want to print only specific field values of a specific issue

Hi, everyone.
To get a specific issue for a particular Jira project, I wrote the following Perl script:

use utf8;
use Filehandle;
use strict;
use warnings;
use Encode;

use JIRA::REST;
use REST::Client;
use JSON;
use Data::Dumper;
use MIME::Base64;

my $jira = JIRA::REST → new({
url => ‘http://company.domaiin:8080’,
username => ‘xxxx’,
password => ‘xxxxxxxx’,
});

Get issue.

my $issue = $jira → GET(“/issue/SMPKB-16”);

my $json_text = do {
open(my $json_fh, “<:encoding(UTF-8)”, $issue) or die (“Can’t open $issue": $!\n”);
local $/;
<$json_fh>
};

my $json = JSON → new;
my $data = $json → decode($json_text);

However, I can not ‘print’ the summary and description fields of a particular issue.
I added a JSON script, but I still get an error (I use JSON for the first time).
I look forward to your help.

Alex.

Hello @netdynamics,

If you only want to return specific fields while using Get issue, use the query parameter fields then specify the fields you need. So for example your GET request will look something like /rest/api/2/issue/SMPKB-16?fields=summary,description.

Do try it out and see if that is what you need.

EDIT:
Upon re-reading the post a number of times, are you more interested about parsing the response body only?

Cheers,
Ian

Hi, iragudo.
Thank you for your explanation.
But my “my $ issue = $ jira -> GET (” / issue / SMPKB-16? “);” Is “my $ jira = JIRA :: REST -> new”. It is a JIRA :: REST perl module.
So I can not change “my $issue = $jira -> GET(”/issue/SMPKB-16?");" to “my $issue = $jira -> GET(”/rest/api/2/issue/SMPKB-16?");".

So I changed and tested as below.

my $issue = $jira -> GET("/issue/SMPKB-16?fields=summary,description");
my $json_text = do {
open(my $json_fh, “<:encoding(UTF-8)”, $issue) or die (“Can’t open $issue”: $!\n");
local $/;
<$json_fh>
};

The following error occurs.
F:\ideaic\perl\site\lib>perl ideaic_interface_jira_get.pl
Can’t open $issue": No such file or directory
F:\ideaic\perl\site\lib>

I printed the “$issue” value. The results are as follows.
get issue: HASH(0x3170d38)

The “hash” value appears to be entering.
How do I print ‘summary’ and ‘description’ values?
Cheers,
Alex

Hello @netdynamics,

HASH is being returned by my $issue = $jira -> GET("/issue/SMPKB-16?fields=summary,description"); in which I think is workable for us. Dumping $issue via Dumper($issue) and printing it results in

$VAR1 = {
          'key' => 'TEST-7',
          'self' => 'http://localhost:2990/jira/rest/api/latest/issue/10100',
          'id' => '10100',
          'expand' => 'renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations',
          'fields' => {
                        'summary' => 'This is a test issue',
                        'description' => 'This is a test description for Perl test'
                      }
        };

In order to get the summary and description, here’s what I did:

my $issue = $jira -> GET("/issue/TEST-7?fields=summary,description");
my $fields = $issue->{fields};
print "summary = $fields->{summary}\n";
print "description = $fields->{description}\n";

which resulted in

Disclaimer:

  1. I only tried perl an hour or so ago to help you with this question, there might be a better way to optimize the code.
  2. JIRA::REST module is new to me too as it is not an Atlassian supported module

I think this should work with your use case.

Cheers,
Ian

1 Like

Hi @netdynamics, does this solve your original question?

Hi, Ian
I sincerely appreciate your help.
I solved it because of your help.
Cheers,
Alex.

1 Like