Forums

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

Setting comments properties while adding comment via API

Jakub Pielużek
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!
March 8, 2023

Hi,
I'm trying to post comment with properties, so it would be an internal comment


post('/rest/api/3/issue/' + createdIssueKey + '/comment')
.header("Accept", "application/json")
.header("X-Atlassian-Token", "nocheck")
.header("Content-Type", "application/json")
.body([
body : fields.comment.comments.body[1],
created:fields.comment.comments.created[1],
author: [
displayName: comment.comments.author.displayName[1]
],
properties: [key: "sd.public.comment", value: [internal: true]]

])
.asJson()

and I'm getting

POST request to /rest/api/3/issue/SD-354/comment returned an error code: status: 400 - Bad Request
body: {"errorMessages":["Invalid request payload. Refer to the REST API documentation and try again."]}
Serializing object into 'interface java.util.Map'

 
I'm trying to not use "Visibility" while posting because I'm running this as ScriptRunner Add-On User and I didn't manage to add this user to specific role to post as this role. 

So either way I need way to add ScriptRunner Add-On User to project roles or fix my code to post comment.

1 answer

0 votes
Barnali Putatunda
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.
March 8, 2023

HI,

When I use this post call: 
url = 'https://' + base_url + '/rest/api/3/issue/'+ issuekey +'/comment'

with the below request body

json_data = {"body":{"version":1,"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":comment}]}]},"properties":[{"key":"sd.public.comment","value":{"internal":True}}]}

Make sure to wrap the comment properties in the way I showed here:
"properties":[{"key":"sd.public.comment","value":{"internal":True}}]

It seems like just a syntax error in your code. Hope it helps!

Suggest an answer

Log in or Sign up to answer