Attach File To Issue API Response Returning Empty Array

Hi,

I'm creating a custom form in which a user can create an issue and attach a file to this issue all in the same form. The first API call will create an issue and then using the API response, I grab the newly created Issue Id to attach their selected file using a second call to the Attach to Issue API.

I seem to be successfully calling to the issue, however, the file does not attach and I receive an empty array ( [] ) as a response.

My code is as follows:


let fileForm = document.getElementById("fileToUpload");
let file = fileForm.files[0];
let formData = new FormData();
formData.append("file", file);
let attachment = formData;

AP.request(attachmentApiUrl, {
type: 'POST',
headers: {
'Authorization': 'Basic myUsername:myPassword',
'X-Atlassian-Token': 'no-check'
},
contentType: 'multipart/form-data',
data: attachment,
success: (resp) => {
console.log(resp) // returns "[]";
},
error: (resp) => {
console.log(resp);
}
});

To be clear, I checked that the content of "file" and "attachment"
is correct and I am getting the necessary values as needed.

Am I missing something here? I'm not using an backend process for reading the file, just a file input (#fileToUpload) and putting it into a formData object which I then send to the API.

0 answers

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

232 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you