I have found several examples on how to upload an attachment to an issue in jira, however I have not been able to make any of them work. I posted this question on the Jira Community Help Forums but it has been over a week with 0 replies so hoping the community here can help.
Here is my current attempt:
$Jirausername = 'myUsername'; $Jirapassword = 'myPassword'; $ch=curl_init();$headers = array(
'X-Atlassian-Token: nocheck',
'Content-Type: multipart/form-data'
);$data = array('file' => "testing.txt");
curl_setopt_array( $ch, array( CURLOPT_URL=>'https://myCompany.net/rest/api/latest/issue/TAG-78/attachments', CURLOPT_POST=>true, CURLOPT_VERBOSE=>1, CURLOPT_POSTFIELDS=>$data, CURLOPT_SSL_VERIFYHOST=> 0, CURLOPT_SSL_VERIFYPEER=> 0, CURLOPT_RETURNTRANSFER=>true, CURLOPT_HEADER=>false, CURLOPT_HTTPHEADER=> $headers, CURLOPT_USERPWD=>"$Jirausername:$Jirapassword"
)
);$result=curl_exec($ch);$ch_error = curl_error($ch);
if ($ch_error) { echo "cURL Error: $ch_error";
} else { var_dump($result);
}curl_close($ch);testing.txt is in the same directory as this file. I have curl installed on the webserver where this is hosted, can create issues in jira fine, just cant seem to upload attahcments...
When I run this page it displays:
string(0) ""
No attachment is uploaded as well needless to say. Any ideas what I am doing wrong?
EDIT: here are some things I have tried:
- trying both nocheck and no-check
- trying both @testing.txt and testing.txt
- removing 'Content-Type: multipart/form-data'
- Full paths as such: $data = array('file'=>"@C:\xampp\htdocs\Website\testing.txt ,'filename'=>'testing.txt');
- Tried like this too because of a known curl error: $data = array('file'=>"@C:\xampp\htdocs\Website\testing.txt" ';filename=testing.txt');
And every combination of those above. No matter what I try it does not work though. Have also ensured I am an admin level user in Jira. I feel like my code should work... but clearly not.