I need to use Rest API to upload some of our automated runs result reports to Jira tickets using nightwatch java script.
Can any one help me fix the 415 response i am getting using the below code :
'Jira: Add Attachment': function (browser) {
//const jira = browser.page.jira();
var request = require('request');
var options = {
method: 'POST',
url: 'https://provinnovate.atlassian.net/rest/api/3/issue/TOQ-633/attachments',
file: {
'file': '/Users/praveennulu/Documents/Github/IntegratedScheduling-master/test_e2e/reports/TestDoc.pdf'
},
headers: {
'Authorization': 'Basic cHJhdmVlbi5udWx1QHByb3ZpZGVuY2Uub3JnOjJ4Nm55WjFpMFdhWFRQRHdKbWJMMDE0Ng==',
'Accept': 'application/json',
'Content-Type': 'application/octet-stream',
'X-Atlassian-Token': 'no-check',
},
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(
'Response: ' + response.statusCode + ' ' + response.statusMessage
);
console.log(body);
});
},
Hi Praveen,
The 415 error code is an indication that your REST call is using the incorrect 'Content-type' header for the file you are trying to upload to Jira. This is explained in more detail in a related Fisheye KB REST API: "Error 415 Unsupported Media Type". I realize that KB is geared for a different product than your Jira Cloud, but the concept is the same here in terms of file attachments via REST.
Instead of using the header of
'Content-Type': 'application/octet-stream'
I think instead this should be something like
'Content-Type': 'application/pdf'
for this particular pdf file.
I hope this helps.
Andy
Even that is also giving me the same 415 response code.
The reason for adding the Content-Type: 'application/octet-stream' was due to the below 500 error i was getting when i don't use any Content-Type .
Response: 500
{"message":"org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/octet-stream","status-code":500,"stack-trace":"java.lang.RuntimeException: org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/octet-stream\n\tat com.atlassian.plugins.rest.common.multipart.fileupload
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Praveen,
It looks like I was mistaken in my last reply. Sorry about that.
You don't actually need to define the content-type when uploading a file via the REST API. I tested this myself using curl and the syntax of
curl --request POST \
--url 'https://example.atlassian.net/rest/api/3/issue/SCRUM-12/attachments' \
--header 'Authorization: Basic {myAPItokenhere}' \
--header 'Accept: application/json' \
--header 'X-Atlassian-Token: nocheck' \
-F "file=@/path/to/file/12345.pdf"
I think that you're getting this error because you are trying to define the content-type here when in fact the documentation on using this endpoint does not indicate to use that specific header. More details in Add attachment POST /rest/api/3/issue/{issueIdOrKey}/attachments.
I believe you should be able to make this work in your python by just removing the 'Content-Type' header entirely.
I hope this helps, please let me know the results.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if you don't define the content'type u got a 500 status error code........
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Praveen Nulu ,
Did you get the answer to this? I am also facing the same issue.
I have added Headers as
1. Content-type: application/json
2. X-Atlassian-Token: nocheck
I have not added
file: {
'file': '/Users/praveennulu/Documents/Github/IntegratedScheduling-master/test_e2e/reports/TestDoc.pdf'
},
but I am adding payload as this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.