When I try and update a comment with a new attachment it fails with:
INFO 09:49:46.063 1e238f12-05f3-4703-be2c-2720d7c4f8fd Update Response: 400 Bad Request
INFO 09:49:46.063 1e238f12-05f3-4703-be2c-2720d7c4f8fd { errorMessages: [ 'ATTACHMENT_VALIDATION_ERROR' ], errors: {} }
What I am doing is roughly:
- Get comment
- Replace an attachment media id with another attachment media id
- Update comment
In code, this looks like this:
// Fetch the comment body
const commentResponse = await api.asApp().requestJira(route`/rest/api/3/issue/${issueIdOrKey}/comment/${commentId}`, {
headers: {
'Accept': 'application/json'
}
});
const commentData = await commentResponse.json();
const commentBody = commentData.body;
// Replace the original attachment ID with the new one
commentBody.content.forEach(contentBlock => {
if (contentBlock.type === 'mediaGroup') {
contentBlock.content.forEach(media => {
if (media.type === 'media' && media.attrs.id === originalAttachmentMediaId) {
media.attrs.id = newAttachmentId;
}
});
}
});
// Update the comment
// Currently this fails with:
// INFO 09:49:46.063 1e238f12-05f3-4703-be2c-2720d7c4f8fd Update Response: 400 Bad Request
// INFO 09:49:46.063 1e238f12-05f3-4703-be2c-2720d7c4f8fd { errorMessages: [ 'ATTACHMENT_VALIDATION_ERROR' ], errors: {} }
const updateResponse = await api.asApp().requestJira(route`/rest/api/3/issue/${issueIdOrKey}/comment/${commentId}`, {
method: 'PUT',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
body: commentBody,
// Include other fields you want to update or keep the same
})
});
console.log(`Update Response: ${updateResponse.status} ${updateResponse.statusText}`);
console.log(await updateResponse.json());
The app already created the new attachment so we know that there aren’t any permission issues there.
I have also tested this across different project types and it’s not limited to JSM or JSW.
There doesn’t seem to be any relevant topics on CDAC either so I am a bit stuck.