Forums

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

Not able to add text in codeblock in comments section

Vineet Bansal May 14, 2020

Hello,

Need to add the SQL output generated in the codeblock of the comments section, below is the command im using.

curl -D- -u $uname:$token -X POST --data @/tmp/a.json -H "Content-Type: application/json" https://abc.atlassian.net/rest/api/3/issue/abc-34716/comment

Error: 

{"errorMessages":[],"errors":{"comment":"Comment body can not be empty!"}}

a.json:

{
"type": "codeBlock",
"attrs": {
"language": "javascript"
},
"content": [
{
"type": "text",
"text": "var foo = {};\nvar bar = [];"
}
]
}

1 answer

1 accepted

0 votes
Answer accepted
Earl McCutcheon
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 18, 2020

Hello @Vineet Bansal ,

As a referance point the Add comment syntax can be seen here:

Then the error you noted is indicating that the "Body" section is missing, 

{"errorMessages":[],"errors":{"comment":"Comment body can not be empty!"}}

Try updating the syntax in your a.json to the following and you should be all set:

{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type":"codeBlock",
"attrs":{
"language":"java"
},
"content":[
{
"type":"text",
"text":"var foo = {};\nvar bar = [];"
}
]
}
]
}
}

It will show up in the comment like this:

Screen Shot 2020-05-18 at 1.50.31 PM.png

Also a really good tip for rapid formatting troubleshooting in comments like this is to add the desired formatting you are trying to troubleshoot, on a test comment from the UI front end, then do a Get comments via GET /rest/api/3/issue/{issueIdOrKey}/comment on the endpoint to see the formatting in action when done system side.

As an exe if you wanted to add in some additional text like the following screenshot:

Screen Shot 2020-05-18 at 2.06.24 PM.png

Run a get on the issue and you will see the additional formatting as:

{
"body": {
"version": 1,
"type": "doc",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "SOME TEXT"
}
]
},
{
"type": "codeBlock",
"attrs": {
"language": "java"
},
"content": [
{
"type": "text",
"text": "var foo = {}; var bar = [];"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Additional text with bullet points:"
}
]
},
{
"type": "bulletList",
"content": [
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "1"
}
]
}
]
},
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "2"
}
]
}
]
},
{
"type": "listItem",
"content": [
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "3"
}
]
}
]
}
]
}
]
}
}

Regards,
Earl

Vineet Bansal May 18, 2020

Thanks a lot Earl for the help, really appreciate it.

Vineet Bansal May 18, 2020

Another related quick question, can we add value from a variable in the text, like this

"text":"$result" ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events