You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I'm having a lot of trouble uploading an attachment to a created issue using the REST API. Currently I'm getting a 415 - "unsupported media type" error.
I would really appriciate some help with this. Thanks!
let actionData=new FormData();
actionData.append('file', files[0]);
actionData.append('comment', "foobar");
actionData.append('minorEdit', "true");
axios({
method: 'POST',
url: jiraApiUrl+'/issue/'+issueID+'/attachments',
headers: {
'X-Atlassian-Token': 'nocheck',
},
data: actionData,
}).then(response => {
//if (!cb) return { error: 'No callback' };
console.log('response-2', response);
return ;//cb(response);
})
.catch((err) => console.log('errorTest - files', err));
I want to post an answer because I've just spent the entire morning figuring this out, and there isn't much discussion on how to do this with axios. Much of the discussion that does exist will suggest to remove the Content-Type header or set it to false, but that did not work for me.
You can set Content-Type to the 'multipart/form-data' as the docs suggest and then calculate the boundary with the form-data library function FormData.getBoundary(). Here is some sample code that should work:
async function testAxiosPost() {
const fd = new FormData();
fd.append('file', fs.createReadStream('./file_name.png'));
const url = 'https://{jira_instance}.atlassian.net/rest/api/2/issue/{issue_key}/attachments';
await axios({
method: 'POST',
url: url,
headers: {
'Authorization': 'Basic {token}',
'X-Atlassian-Token': 'nocheck',
'Content-Type': 'multipart/form-data; boundary=' + fd.getBoundary()
},
processData: false,
cache: false,
data: fd
})
.then((response) => console.log(response))
.catch((e) => console.error(e.response));
}
This worked for me. Thank you!
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.
Abdul, did you ever get this figured out? I'm having the same problem. So far I have gotten 404, 415 and 500 errors. I can upload via Postman but when I try to use an Axios call it stops working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure about using axios, but from looking at other instances with this error such as
How to change the mediatype of an attachment via REST API
REST API error 415 unsupported media type
It seems like this might be a problem with a lack of a content type paramenter. I think you might need to clarify the request by adding a
'Content-Type: application/json'
somehow to this REST. But I also think you will need to modify the
'X-Atlassian-Token': 'nocheck'
to be
'X-Atlassian-Token: nocheck'
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.