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
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.