Reputation: 641
I am using Jira rest API to create an issue with attachment. I have created issue ticket successfully with summary and description but I am facing issues in adding an attachment with Jira issue.
how can I add an attachment to Jira issue using rest API in PHP curl request?
i am using this code to add an attachment.
$url = 'https://domain.atlassian.net/rest/api/2/issue/PL-113/attachments';
$fileLocation = 'D:/xampp/htdocs';
$fileName = 'test.jpg';
$username = 'username';
$password = 'password';
$data = array('file'=>"@{$fileLocation};filename={$fileName}");
$headers = array(
'X-Atlassian-Token: nocheck'
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
$ch_error = curl_error($curl);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
echo $result;
}
curl_close($curl);
Thanks in advance
Upvotes: 3
Views: 1743
Reputation: 711
Based on the baseUrl you used in the sample, I assume you are working with Jira Cloud. Given the issue ID, you can add attachments by calling Add attachment REST API.
Upvotes: 1