Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to inline images in Issue body or issue comment body

William Hoyle
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 7, 2021

I am writing a custom Service Desk portal for my organization. 

 

I am using the jira REST API (with Basic "token" auth) to query issues/issue comments (with JQL) on a server. In general, this is working okay since the issue and issue/<key>/comment endpoints return a renderedBody field with the HTML. I can display the HTML on the webpage without requiring an ADF renderer.

 

The issue is how can we go the other way? For example, I want users to be able to create tickets from my custom Service Desk webpage. From what I can tell, there's two options:

 

1. Use REST API v2: https://airps.atlassian.net/rest/api/2/issue/<key>/comment 

The body field takes a string. Seems like I can't post any rich HTML text at all so that's probably no good.

 

2. Use REST API v3: https://airps.atlassian.net/rest/api/3/issue/<key>/comment 

The body field takes an ADF object. 

I can post to that endpoint:

{ version: 1, type: 'doc', content: [ { type: 'paragraph', content: [ { type: 'text', text: 'test internal' } ] } ] }

 

How can I embed images and files in a comment? Could I first create an attachment on the issue, get the link, and post it as a mediaSingle node type as follows?

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

 

What are my options for Editors? I need to choose an editor that can output the user's comment to ADF. This is assuming the image/files issue above can be solved. 

 

This whole thing feels hacky to be honest. Am I going about this the wrong way? What is the best way to create my own support webpage (support.mycompany.com)? We want to control the entire experience and integrate our own auth system (that's why we're not interested in building a Connect/Forge app)

 

Thanks,

 

Will

 

1 answer

1 accepted

4 votes
Answer accepted
Sunny Ape
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 7, 2021

Hello @William Hoyle 

Your question has the tags cloud and jira-cloud, but your first sentence says "on a server", so it's not clear if you're using Jira Cloud or Jira Server.

For both, the v2 endpoints supports using markdown syntax to format descriptions and comments, but it still requires that you first attach the image to the issue, then get its ID, then reference that ID in the inserted hyperlink.

With Cloud and the v3 endpoints, you must use the ADF format to build the description and comment contents. You still need to add the attachment to the issue, get its ID, then reference that ID inside the mediaSingle node declaration. There is also currently a limit to the media API in that it doesn't allow it to be used to lookup that ID.

ADF is a bit painful, as it's like nothing else on this planet and there are no off the shelf libraries or 'editors' to convert HTML, XML, or the old markdown etc. to ADF.... so you have to do it all in code, yourself. There are plenty of threads on the Jira Developer community discussing this and related topics.

At the moment, I'm personally still using the v2 endpoints if I want to add detailed descriptions and comments to issues until the v3 endpoints have matured more and have a better mechanism for parsing non ADF data into ADF format.

William Hoyle
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 7, 2021

Hi @Sunny Ape ,

 

Thanks for the quick reply. I should have been more clear. I'm using JIRA Cloud and querying the v2/v3 endpoints from my own server.

 

It's too bad there isn't a better way to do this. I will use the v2 endpoints then. I wish they had chosen a more common format to store description/comments.

 

Thanks

Like Sunny Ape likes this

Suggest an answer

Log in or Sign up to answer