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 am trying to add attachment by using the two API POST /rest/servicedeskapi/servicedesk/{serviceDeskId}/attachTemporaryFile and servicedeskapi/request/{issueIdOrKey}/attachment
I use a popup to upload the attachement and this is How i retrieve it
let file =document.getElementById(idElement);
let formData = new FormData();
formData.append('file', file.files[0]);
and then i pass it to this function:
function addAttachment(keyOrId, comment, formData) {
const requestData = {
"temporaryAttachmentIds": [],
"public": true,
"additionalComment": {
"body": comment
}
};
AJS.$.ajax({
url: restUrl,
type: "POST",
processData: false,
contentType: "multipart/form-data",
headers: {
"X-Atlassian-Token": "no-check",
"X-ExperimentalApi": "opt-in"
},
data: file,
success: function(response) {
// The file was uploaded successfully, so attach it to the issue
const attachmentId = response.temporaryAttachmentId;
requestData.temporaryAttachmentIds.push(attachmentId);
AJS.$.ajax({
url: attachurl,
type: "POST",
contentType: 'application/json; charset=UTF-8',
headers: {
"X-Atlassian-Token": "no-check",
"X-ExperimentalApi": "opt-in"
},
data: JSON.stringify(requestData),
success: function(response) {
// The file was attached to the issue successfully
console.log("File attached to issue successfully");
},
error: function(jqXHR, textStatus, errorThrown) {
console.error(`Error attaching file to issue: ${errorThrown}`);
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
console.error(`Error uploading file: ${errorThrown}`);
}
});
}
but it does not work and does not show any errorr. Anyone could tell me what I am doing wrong?