Hi and thank you for taking the time to read my question!
I want to add a comment to an issue through the API.
I can successfully add a comment to an issue and I can also successfully add an attachment to the issue. The problem is that I want to add an image IN a comment. On the Jira Website you can drop an image or add one through an explorer, so it is possible.
When I query an issue with an image as comment I see it as:
I thought of adding a comment with this structure, but I'd need the ID to link the attachment. The ID of the comment attachment is super long ("4f190z82-945d-4be6-cb21-9a815fb7f1v") while the ID of the uploaded attachment is much shorter (23575).
Is there something I'm missing, or is adding an image as comment not possible through the API?
You can attach a file or image via the REST API in Jira. The thing to understand about doing this though is that it is not the exact same REST endpoint used to post a comment to an issue in Jira. I understand that since you can drag/drop an image in the comment box of Jira's web UI the appearance might be that you can do this in a single go. But when you do that, the image is actually being uploaded to the issue before you actually submit your comment. (You can test this by dragging an image file into a comment in Jira, and then not actually submitting your comment by then pressing 'Cancel', the image will still remain attached to the Jira issue).
So there are actually two different steps happening here, even in the web UI. In your case, I believe you're going to need to call two separate rest endpoints to make this work as well. Also you would need to make sure that the file attachment endpoint is being called first.
The KB on How to add an attachment to a JIRA issue using REST API explains how to upload images to Jira via the REST API.
Once the file is attached to the issue in question, then the steps need to reference that image in the comment is just using the wiki markup syntax to reference the filename of that image. So in Jira, if your attachment name was testimage.png, you can make your comment look something like this
test message here
see my image above
I hope this helps.
This one took me a while to figure out with a lot of trial-and-error, so I feel I should share to save the world some time.
I am using Jira Cloud, so all the documentation pushes you to V3 API, which uses Atlassian Document Format. There is a section for embedding attachments under Node - media, however the documentation says you need to pass in an ID which you can get by "...querying the media services API to retrieve metadata, such as, filename. Consumers of the document should always fetch fresh metadata using the Media API." I have found no documentation on a "Media API", so I gave up on V3.
However, you can use the V2 Add Comment API in Jira Cloud.
First you call the Add Attachment API.
Response (trimmed for brevity)
Using the "content" or "thumbnail" value, call the V2 Add Comment API and surround the value with ! on either end:
"body": "Here is my image !https://your-company.atlassian.net/secure/attachment/12345/image-20210221-170959.png!"
This also works if you are adding comments via the "External System Import":
TP-3,"Test API Issue","2021-02-21 03:00:00;5e5e5e5e5e5e5e5e5e5e5e5e;Here is my image !https://your-company.atlassian.net/secure/attachment/12345/image-20210221-170959.png!"
Connect with like-minded Atlassian users at free events near you!Find an event
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no Community Events near you at the moment.Host an event
You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events