Hi, I’m currently developing an Issue Action Application that copies the most recent comment into linked issues. However, I’m running into problems posting comments that include Attachments. I’ve tested my current code and it seems to work perfectly fine posting everything except comments with attachements. When I try to copy a comment with an attachment to other issues, I get a 400 error indicating the request is invalid. Help!
//function to add a comment given an issue Id and a body
async function addComment(issueId, body) {
const requestUrl = `/rest/api/3/issue/${issueId}/comment`;
const newbody = {
"body": body
}
console.log(newbody);
console.log(newbody.body);
console.log(newbody.body.content);
// Use the Forge Runtime API to fetch data from an HTTP server using your (the app developer) Authorization header
let response = await api.asApp().requestJira(requestUrl, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(newbody)
});
console.log(`posted new comment`);
// Error checking: the Jira issue comment Rest API returns a 201 if the request is successful
if (response.status !== 201) {
console.log(response.status);
throw `Unable to add comment to issueId ${issueId} Status: ${response.status}.`;
}
return response.json();
}