Add comment on Jira Cloud by api rest with Markups

Hello,

I’m trying to write a comment with a wiki markup by api rest, but when i use the api request, it escapes the special characters.
How can I solve that?.

My code:

def tempCommentBody = “{color:red} This is red {color} " + commentBody
def result = post (”/rest/api/3/issue/${issueIdOrKey}/comment")
.header(“Content-Type”, “application/json”)
.header(“Accept”, “application/json”)
.body([
“visibility”: [
“type”: “role”,
“value”: roleType
],
“body”: [
“type”: “doc”,
“version”: 1,
“content”: [
[
“type”: “paragraph”,
“content”: [
[
“text”: tempCommentBody,
“type”: “text”
]
]
]
]
]
])

Hi @JuanFranciscoSacrist,

Sorry we’ve been so slow to reply here! You need to specify the body in Document Format, markup won’t work - but there’s a pretty handy tool to help - check out the document builder at Document builder

For example, to display part of your text in red you’d use:

  "version": 1,
  "type": "doc",
  "content": [
    {
      "type": "paragraph",
      "content": [
        {
          "type": "text",
          "text": "This is red ",
          "marks": [
            {
              "type": "textColor",
              "attrs": {
                "color": "#ff5630"
              }
            }
          ]
        },
        {
          "type": "text",
          "text": "but this is not. "
        }
      ]
    },
    {
      "type": "paragraph",
      "content": []
    }
  ]
}

Hope this helps, even though it’s a few months late.

Cheers,
Mel

1 Like

Hi @mpaisley, that playground works only for text and not for images. Please confirm. Thanks.

Hey @Nishanth.Thimmareddy,

Ahh I see - embedding media, like images, into comments via the API is a little more complicated.

When creating a comment using Document Format, the elements you’d need to use are the Node - mediaSingle, Node - mediaGroup and Node - media, however you’ll also need to use the Media API.

Here’s a sample of what the document body of a comment that includes an embedded image might look like:

"body": {
        "version": 1,
        "type": "doc",
        "content": [
            {
                "type": "paragraph",
                "content": [
                    {
                        "type": "text",
                        "text": "This comment includes an image of a cat I uploaded"
                    }
                ]
            },
            {
                "type": "mediaSingle",
                "attrs": {
                    "layout": "align-start"
                },
                "content": [
                    {
                        "type": "media",
                        "attrs": {
                            "id": "7faaa732-eda0-48aa-aba0-6b97b91c7f01",
                            "type": "file",
                            "collection": "jira-10082-comment-10142",
                            "width": 250,
                            "height": 250,
                            "occurrenceKey": "bdf04c9c-327c-412c-9cf8-34d7af83b442"
                        }
                    }
                ]
            }
        ]
    }

As you can see, there’s a non-trivial ‘id’ that you need to include for the Media you’re embedding in your comment. That comes from the Media API. I’m looking into whether the Media API is available outside Atlassian.

Cheers,
Mel

Unfortunately the Media API is not available publicly, and no Jira Cloud API has been implemented to provide it at this time.

You are welcome to create a Suggestion via the Atlassian Public Issue tracker if this is something you’d like to see in the future.

Please keep in mind when creating the suggestion that it helps to include why you’d like to see this feature, and how Atlassian teams prioritise feedback.

Finally, remember to share your Jira Issue link here so other developers can use the link to vote or watch the ticket.

Cheers!
Mel

Yes @mpaisley, thanks for the quick analysis, this is something we need asap as its breaking our apps when we try to copy comments or in fact any text area field where this cloud editor is used. We will raise a DEVHELP for this. Thanks again.

Hi Nishanth,

You should raise a suggestion in the public Jira issue tracker at System Dashboard - Create and track feature requests for Atlassian products. then share the ticket here.

Cheers,
Mel

1 Like

Hi @mpaisley , do you know if there is an update way to include images via REST API at this point?