I can add an attachment to an existing issue from the command line using cURL as follows:
curl -D- -u testuser:testuser -X POST -H "X-Atlassian-Token: nocheck" -F "file=@test.txt" http://localhost:8090/rest/api/2/issue/TES-1/attachments
However, when I try to execute the same code from PHP using what I believe to be the exact same parameters, I recieve an "HTTP Status 415 - Unsupported Media Type". Here is the code:
<?php
$username = 'testuser';
$password = 'testuser';
$url = "http://localhost:8090/rest/api/2/issue/TES-1/attachments";
$data = array (
'file'=>'test.txt'
);
$ch = curl_init();
$headers = array(
"X-Atlassian-Token: nocheck",
'Content-Type: application/json'
);
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_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
$ch_error = curl_error($ch);
if ($ch_error) {
echo "cURL Error: $ch_error";
} else {
echo $result;
}
curl_close($ch);
?>
TIA.
Community moderators have prevented the ability to post new answers.
NOTE:
X-Atlassian-Token: nocheck
is not correct header value. It should be:
X-Atlassian-Token: no-check
For some reason our Jira 5.2 version only works with "nocheck" value. With "no-check" I still get "jira.utils.JIRAError: JiraError HTTP 404 text: XSRF check failed"
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.
POST /rest/api/2/issue/sdlcdevops-3238/attachments HTTP/1.1
Host: wim-jira.wellsfargo.com
X-Atlassian-Token: no-check
Authorization: Basic dTU3NjI3MjpGcmVtb250MTIz
Cache-Control: no-cache
Postman-Token: 94a3b1aa-454e-b976-b6e9-202ee407b753
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="agent.py"
Content-Type:
------WebKitFormBoundary7MA4YWxkTrZu0gW--
This has worked for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
content type should be "multipart/form-data"
check some sample code in other languages
http://stackoverflow.com/questions/11886316/how-to-post-attachment-to-jira-using-rest-api
http://stackoverflow.com/questions/18631361/add-attachment-to-jira-via-rest-api<br< a="">>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Progress, I think. Now I get the following error.
FileUploadException: the request was rejected because no multipart boundary was found
In the CLI, it seems like cURL takes care of setting the boundary -- Not sure if I have to set it manually.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried removing 'Content-Type: application/json' but the result is the same.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
$headers = array(
"X-Atlassian-Token: nocheck",
'Content-Type: application/json'
);
Shouldn't the above be only X-Atlassian-Token: nocheck and not both?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.