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.
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?
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
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";