Not able to get the complete IssueLinks field via PHP and Curl in JIRA API

Aruna U March 20, 2023

I am not sure what happened recently. My Curl Request written in PHP to get Linked issues in a JIRA story is not getting the entire field rather than the first object. Meaning, If there are more than one Linked issues, the CURL request returns only the first linked issue details and none following it.

I know my code worked completely fine last month but suddenly starting last week, seeing this kind of issue.

If I use the API URL, https://track-api.[my-company].com/jira/rest/api/2/issue/[Issue-ID]?fields=issuelinks , I am able to see all the linked issues. While using the same in CURL request is not working fine.

I see this issue of first object being returned only with 'issueLinks' field and all other fields are getting returned completely fine with right values.

Is this an existing issue by any chance or something happening to me alone?

 

Here is my code to fetch issue details:

public static function getIssueDetails($id){
try {
$url="https://track-api.[my-company].com/jira/rest/api/2/issue/$id";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// Set key and cert
curl_setopt($ch, CURLOPT_SSLCERT, self::$certFile);
curl_setopt($ch, CURLOPT_SSLKEY, self::$keyFile);

// execute!
$result = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception(curl_error($ch));
}
curl_close($ch);

return Array(
'status' => true,
'data' => json_decode($result,true),
);
} catch(Exception $ex) {
return Array(
'status' => false,
'data' => $ex->getMessage(),
);
}
}

}

 

1 answer

0 votes
Oday Rafeh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2023

Hi @Aruna U , 

Your code seems to be working correctly for fetching the issue details, including the issue links. However, you mentioned that you're only getting the first linked issue. This might be due to how you are processing the returned data in your application after making the cURL request.

Please make sure that you're correctly iterating through the "issuelinks" field in the response data. Here you can see  how to process the "issuelinks" field in the response data:

$response = getIssueDetails($issueID);
if ($response['status']) {
$issueData = $response['data'];
if (isset($issueData['fields']['issuelinks'])) {
$issueLinks = $issueData['fields']['issuelinks'];
foreach ($issueLinks as $link) {
// Process each issue link here
// For example, you can access the linked issue key using $link['inwardIssue']['key'] or $link['outwardIssue']['key']
echo "Link type: " . $link['type']['name'] . "\n";
if (isset($link['inwardIssue'])) {
echo "Inward issue key: " . $link['inwardIssue']['key'] . "\n";
}
if (isset($link['outwardIssue'])) {
echo "Outward issue key: " . $link['outwardIssue']['key'] . "\n";
}
}
}
} else {
echo "Error: " . $response['data'];
}
Aruna U March 20, 2023

Hi @Oday Rafeh ,

Thank you for your quick response. I see the issue when I print the response itself before even start to process the 'issueLinks' field. If I try to do a print_r($result) in my above code, I am able to see only the first linked issue and not more than that.

My code worked fine earlier and its very recently I see this issue to be happening.

Oday Rafeh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2023

Hi @Aruna U 

Thank you for the clarification. If you're only seeing the first linked issue when printing the raw response itself, it could be an issue with the Jira API or a limitation on the number of results being returned.

Aruna U March 20, 2023

Thank you @Oday Rafeh . Any idea on how can I escalate this further to understand the root cause and get this solved?

Oday Rafeh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 20, 2023

@Aruna U 

Well, You can try this to troubleshoot the issue:

Check for API changes: Review the Jira API documentation and release notes to see if there have been any changes to the API that could be causing this issue.

Examine the API response size: There might be a limit to the response size, causing the API to truncate the results. You can check the response headers for any indications of this. If it's the case, you might need to adjust the pagination settings in your API request to retrieve more results.

Verify the issue links in Jira: Double-check the issues in Jira's web interface to make sure the issue links are set up correctly and that there are multiple linked issues present.

Test the API request with other tools: Use other tools like Postman or curl from the command line to test the API request and see if you get the same results. This can help rule out any issues related to your PHP code or environment.

Suggest an answer

Log in or Sign up to answer