Jira REST API upload attachment PHP

Justin Lyson June 2, 2017

I have searched and found many "working" examples but every time I try nothing happens. Here is my current code:

 

   $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://XXXX.net/rest/api/latest/issue/TSP-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);

 

 

This returns "string(0) "" " to my webpage when I call this. Attachment it not uploaded. testing.txt is in the same folder the script is being run from. Am I doing the path or something wrong? Please help.

2 answers

0 votes
Midas Technologies Support Team November 16, 2021

"$Jirausername:$Jirapassword" in php array is wrong format

0 votes
Justin Lyson June 6, 2017

bump.... Anyone help?

Suggest an answer

Log in or Sign up to answer