The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Getting error "Comment body can not be empty!" when trying to add a comment by REST API

Adam Rypel _MoroSystems_
Community Champion
February 2, 2022

As described in the summary - I am using ScriptRunner. Here is the code I am trying to run:

 def commentBody = [
"type": "doc",
"version": 1,
"content": [
"type": "paragraph",
"content": [
"type": "text",
"text": "The group could not be created. Response:"
]
]
]

post("/rest/api/3/issue/GS-1/comment")
.basicAuth(SERVICE_USER, SERVICE_API_TOKEN)
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.body(commentBody)
.asJson()

 Here is the response:

POST request to /rest/api/3/issue/GS-1/comment returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"comment":"Comment body can not be empty!"}}

I followed ADF documentation here: https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/

Any idea where the problem could be?

Thanks!

2 answers

2 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
February 3, 2022

Hi @Adam Rypel _MoroSystems_ , the correct format of the request is:

 

 def commentBody = [ body: [
type: "doc",
version: 1,
content: [
[
type: "paragraph",
content: [
[
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
type: "text"

]
]
]
]
]]
Adam Rypel _MoroSystems_
Community Champion
February 4, 2022

Thanks! This one works as intended

0 votes
Answer accepted
Tim Perrault
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 Champions.
February 3, 2022

Hi @Adam Rypel _MoroSystems_ 

 

The errors is saying it's missing the body part to the actual api post. Could you try updating your code and see if this helps.

 

def commentBody = {"body":
[
"type": "doc",
"version": 1,
"content": [
"type": "paragraph",
"content": [
"type": "text",
"text": "The group could not be created. Response:"
]
]
]
}

 

Thanks,

Tim

Adam Rypel _MoroSystems_
Community Champion
February 4, 2022

Thanks! Body was indeed the problem, just had to adjust syntax as Martin said:

 def commentBody = [ body: [
type: "doc",
version: 1,
content: [
[
type: "paragraph",
content: [
[
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eget venenatis elit. Duis eu justo eget augue iaculis fermentum. Sed semper quam laoreet nisi egestas at posuere augue semper.",
type: "text"

]
]
]
]
]] 
Like • Tim Perrault likes this
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events