Hi
I'm now working on attaching attachment for issues based on REST API using PHP. This is my code:
<?php
$ch=curl_init();
$headers = array(
'X-Atlassian-Token: nocheck',
'Content-Type: multipart/form-data'
);
$data = array("file" => "attachments/test.txt");
curl_setopt_array(
$ch,
array(
CURLOPT_URL=>'http://localhost:8080/rest/api/latest/issue/IS-23/attachments',
CURLOPT_POST=>true,
//CURLOPT_HTTPGET =>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=>"test:test"
)
);
$result=curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
var_dump($result);
}
curl_close($ch);
?>
=============
However, I could got any result. Any ideas?
Thanks
Hi All,
Just confirmed that it is working well on cURL (PHP 5.6)
public function upd_to($resource, $data, $issueID, $jiraURL, $jiraUserName, $jiraUserPassword)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_POST => 1,
CURLOPT_URL => $jiraURL . '/rest/api/latest/' . $resource . '/' . $issueID . '/attachments',
CURLOPT_USERPWD => $jiraUserName . ':' . $jiraUserPassword,
CURLOPT_POSTFIELDS => $data,
CURLOPT_VERBOSE => 0,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('X-Atlassian-Token: nocheck')
));
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
Please pay attention to:
$data = array(
'file' => curl_file_create($filePath)
);
For PHP 5.5+ we should use "curl_file_create" function instead of:
$upd_issue = array(
'file' => "@" . $filePath . ";filename=" . "TEST.mp3"
);
The following code works for me (tested on JIRA version 6.3.12):
<?php $ch=curl_init(); $headers = array( 'X-Atlassian-Token: nocheck', 'Content-Type: multipart/form-data' ); $data = array("file" => "@filepath/filename.png;filename=filename.png"); curl_setopt_array( $ch, array( CURLOPT_URL=>'http://localhost:8080/rest/api/latest/issue/TEST-01/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=>"userid:password" ) ); $result=curl_exec($ch); $ch_error = curl_error($ch); if ($ch_error) { echo "cURL Error: $ch_error"; } else { var_dump($result); } curl_close($ch); ?>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,you should add '@' character before the file example :@file.txt and you will have your file attached @carol yang @Nicholas Ng
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have the same problem adding attachment via PHP REST API. Anybody have any working code example or point to some refernece?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.