Forums

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

Api V3 add or copy comment with picture (groovy)

Aleksandar
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!
May 8, 2020

Hello

I am unable to create a copy of existing comment to another issue (using rest api V3 and groovy on Jira Cloud) if it contains image ("type": "mediaSingle"). For example, I can grab a comment with this code:

def commentToAdd = get("/rest/api/3/issue/${issueKey}/comment/15513")
.header('Content-Type', 'application/json')
.asObject(Map)
.body
bodyToAdd = commentToAdd.body

Then I try to create a new comment:

def commentResp = post("/rest/api/3/issue/${targetIssueKey}/comment")
.header('Content-Type', 'application/json')
.body("body": bodyToAdd)
.asObject(Map)
assert commentResp.status == 201

 If comment contains picture, code will return error:

status: 400 - Bad Request body: {errorMessages=[], errors={comment=Comment body is not valid!}}

If comment does not contain picture (if it has only paragraphs), comment will be created.

I tried to remove picture from content array and when I do so, comment will be created. To test this, I iterated through content array and and ignored all types other than paragraph:

def newContent =[]
for (contentLine in commentToAdd.body.content){
if(contentLine.type == 'paragraph')
newContent.add(contentLine)
}
bodyToAdd = [version: 1, type: "doc", content: newContent]

When this code is executed before calling previous code with post, the comment will be created, and the picture will obviously not be there, because it was skipped.

Does anyone have a suggestion what may be wrong? Thanks

1 answer

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
May 11, 2020

Hi Aleksandar,

Thank you for your question.

I have looked at your issue and can confirm the reason why you get the error stating that the body is invalid when you try to copy the comment with the picture is due to the fact that Atlassian do not support adding or copying pictures or attachments through any of there comment API's.

The reason for this is that Atlassian do not provide any access to the file system as part of the restrictions they impose on Jira Cloud which means no API calls can access the attachments on an issue to copy them.

I understand that this response is frustrating but please note that it is not possible to create or copy comments with pictures due to the API limitations imposed by Atlassian as mentioned above and ScriptRunner for Jira Cloud is unable to work around these as it can only use the API's which Atlassian provides in Jira Cloud.

I hope this information helps.

Regards,

Kristian

Aleksandar
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!
May 11, 2020

Thank you for the reply. Do you have any suggestion on how to handle this? I could block comment content per top level block node. Is it enough to block (omit from copied comment) mediaGroup and mediaSingle? Are there any other restrictions I should be aware of?

Top-level block nodes

Kristian Walker _Adaptavist_
Community Champion
May 11, 2020

Hi Aleksander,

I am not aware of any other restrictions myself and believe all the other wiki markup for formatting should be copied but would advise testing this on a test issue in your local instance. 

I would advise to just check if a comment has a picture in it and if it does to remove this from the comment body as you have been doing.

I hope this information helps.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events