Add attachment to an issue using JQUERY

Hello,

Will appreciate some assistance here please...

We have been able to use the below JSON file to open up an issue in JIRA.

However, we want to take this a step further... We will like to add an attachment to this issue, either via:

1. When issue is originally opened usig below JSON file.

OR

2. Use the issue number created from below file, to add an attachment to issue.


{
"fields": {
"issuetype":
{ "name": "Letter of Greeting" }
,
"project":
{ "key": "CCOPS" }
,
"customfield_10063": "City/Town",
"customfield_10101": "Charitable Organization Number",
"customfield_10069":
{ "value": "Pending" }
,
"customfield_10070":
{ "value": "Pending" }
,
"customfield_10102": "URL",
"labels": [ "greeting" ],
"customfield_10103": [
{ "value": "By clicking this button I confirm that I am the Official Representative of the Organization requesting the Proclamation" }
],
"customfield_10016": "Organization Name",
"customfield_10017": "Event Name",
"customfield_10018": "2016-11-28",
"customfield_10019":
{ "value": "Convention" }
,
"assignee":
{ "name": "mhelly", "key": "mhelly" }
,
"description": "Description",
"customfield_10011": "Province",
"customfield_10012": "Postal Code",
"customfield_10014": "Additional Notes",
"customfield_10015": "2016-11-27",
"customfield_10005": "Telephone Number",
"summary": "Please enter a summary for this Service Request.",
"customfield_10081": "Street Number",
"customfield_10082": "Street Name",
"customfield_10083": "Unit Number",
"customfield_10084": "First Name",
"customfield_10085": "Last Name",
"customfield_10086": "Email@Email.Email",
"reporter":
{ "name": "CCO_Webmaster", "key": "CCO_Webmaster" }
}
}

1 answer

1 vote
Volodymyr Krupach Community Champion Nov 29, 2016

Hi Volodymyr,

I looked to curl command  but 

my point is to use JQUERY to get this job done.

Here is my code:

var formdata = new FormData();
formdata.append('tasks', "C:\01-Rosana-Protocol\NOV-2016\Tasks10.txt");
formdata.append('tabs', "C:\01-Rosana-Protocol\NOV-2016\chroom tabs10.txt");
_.forEach(formdata.entries(), function (value, key) {
console.log(key);
});
for (var k in formdata.entries()){
console.log(k[0]+ ', ' + k[1])
}

$.support.cors = true;
$.ajax({
type: "POST",
url: "http://Mvclkpro01d.corp.toronto.ca:8080/rest/api/2/issue/CCOPS-50/attachments",
data: formdata,
contentType: false,
processData: false,
headers: {
"X-Atlassian-Token": "nocheck"
},

// contentType: "multipart/form-data; boundary=HereGoes",
contentType: "multipart/form-data",
success: function (data, status, req) {
alert("Data Loaded : " + data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert('responseText ' + jqXHR.responseText);
alert('error in uploading:: ' + errorThrown);
}
});//Ajax
});//click

 

After executing this AJAX call I got nothing uploaded into JIRA isssue

 

Thanks for your help

Volodymyr Krupach Community Champion Nov 29, 2016

I never did multipart file upload via jQuery and I guess it's restricted by due to security reasons. Please debug your request to check if files are actually send.

Please consider doing this via html form.

Suggest an answer

Log in or Join to answer
Community showcase
Emilee Spencer
Published Friday in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

56 views 0 3
Read article

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot