Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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? Edited

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.

Capture.PNG

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?

2 answers

0 votes
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
 !testimage.png|thumbnail!
see my image above

I hope this helps.

Andy

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.

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)

{
"self":"https://your-domain.atlassian.net/rest/api/2/attachments/12345",
"id":"12345",
"filename":"image-20210221-170959.png",
"content":"https://your-company.atlassian.net/secure/attachments/12345/picture.jpg",
"thumbnail":"https://your-company.atlassian.net/secure/thumbnail/12345/picture.jpg"
}

 

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 !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":

JiraKey,Summary,Comment
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!"

Suggest an answer

Log in or Sign up to answer
TAGS

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