Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Attachment with Rest API Issue

Benny March 3, 2021

I am attempting to add an attachment to an existing issue with PHP/CURL. In the process of adding the attachment I am getting the following response which is not appearing as an CURL error. When I check the issue in the Jira app There is no attachment.


Response:
string(917) "HTTP/1.1 100 Continue HTTP/1.1 200 OK Server: AtlassianProxy/1.15.8.1 vary: Accept-Encoding cache-control: no-cache, no-store, no-transform Content-Type: application/json;charset=UTF-8 Strict-Transport-Security: max-age=315360000; includeSubDomains; preload Date: Wed, 03 Mar 2021 16:20:46 GMT ATL-TraceId: 4c8e7389f498ea4a x-arequestid: ***** x-aaccountid: ***** X-XSS-Protection: 1; mode=block Transfer-Encoding: chunked timing-allow-origin: * x-envoy-upstream-service-time: 74 X-Content-Type-Options: nosniff micros-issuer: micros/edge-authenticator Connection: keep-alive set-cookie: atlassian.xsrf.token=BAEM-P7IG-5EIU-1CCG_5975e1698d2a1fac38b5077c26755783966983ec_lin; Path=/; Secure Expect-CT: report-uri="https://web-security-reports.services.atlassian.com/expect-ct-report/global-proxy", enforce, max-age=86400 []"

This is the code snippet I am using to add the attachment.

$issueKey = $list_issues['key'];
$filepath = realpath('../JIRA_app/file/');
$name = "\test.txt";

$username = USERNAME;
$token = TOKEN;
$url= "https://*******.***/rest/api/3/issue/".$issueKey."/attachments/";
$header = array('Content-Type: multipart/form-data','X-Atlassian-Token: no-check');
$ch = curl_init();
$data = array('file'=>"@{$filepath};filename={$name}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS ,$data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$token");

$result = curl_exec($ch);
$ch_error = curl_error($ch);

if ($ch_error)
{
echo "cURL Error: $ch_error";
}
else
{
var_dump($result);
}
curl_close($ch);





0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events