Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I add an image in a comment?


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:

"content": [
"type": "mediaSingle",
"attrs": {
"layout": "center"
"content": [
"type": "media",
"attrs": {
"id": "4f190z82-945d-4be6-cb21-9a815fb7f1v",
"type": "file",
"collection": "",
"width": 200,
"height": 183


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?

4 answers

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.

POST /rest/api/2/issue/{issueIdOrKey}/attachments

Response (trimmed for brevity)



Using the "content" or "thumbnail" value, call the V2 Add Comment API and surround the value with ! on either end:

POST /rest/api/2/issue/{issueIdOrKey}/comment

"body": "Here is my image !!"


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 !!"
1 vote

Workaround using only V3 API:

  • add attachment
  • get attachment data
  • get "content" url without following redirections. The response will be a redirection, and the location contains the media ID.

PHP sample code:

$r1 = \Unirest\Request::get('/attachment/'.$attachment->id, [
'Accept' => 'application/json'

\Unirest\Request::curlOpt(CURLOPT_FOLLOWLOCATION, false);
$r2 = \Unirest\Request::get($r1->body->content);
\Unirest\Request::curlOpt(CURLOPT_FOLLOWLOCATION, true);

if ($r2->code === 302 && isset($r2->headers['location']) &&
preg_match('|/file/([^/]+)/|', $r2->headers['location'], $matches)) {
$mediaId = $matches[1];
1 vote
Andy Heinzer Atlassian Team Dec 03, 2018

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.


As Andy said, you have to attach the image to the issue first and know what its ID is before you can refer to it.

Insert it like external url

version: 1, type: 'doc', content: [ { "type": "mediaSingle", "content": [ { "type": "media", "attrs": { "type": "external", "url": "", "width": 710, "height": 163, } } ] } ]

works perfect

Suggest an answer

Log in or Sign up to answer

Community Events

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

Events near you