It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Code 400 when add cpmment via REST

Hello everybody. I try to comment Issue via REST API and have 400 code, which means input is invalid. 

http.request(POST, ContentType.JSON) {
requestContentType = ContentType.JSON
request.addHeader("authorization: Basic ${authString}", "ContentType: application/json")
body = ["body": "${commentBody}"]
response.success = { resp, reader ->
log.warn("Issue commented successfully " + resp.status.toString())

response.failure = { resp ->

But via curl it works

curl -i -u "user:password" -H "Content-type: application/json" -H "Accept: application/json" -d"{\"body\":\"Comment via REST API \"}" -X POST https://{jiraAddress}/rest/api/2/issue/{issueId}/comment -o myfile.txt

Even when I add all parameters mentioned here I have 400 code

1 answer

1 accepted

0 votes
Answer accepted
Hana_Kučerová Community Leader Nov 01, 2019


I believe, the problem is that you don't send valid JSON in your request body (that's why the input is invalid, because it is not possible to parse it)

Is your request's body transformed automatically and correctly to JSON? 

It should look like this:

{"body" : "test message"}


I've tried to debug it a little bit more.

Instead of 

body = ["body": "${commentBody}"]


body = [body: "${commentBody}"]

 It works for me.

Hi Hana! Thanks for help. The error message was 

{errorMessages=[Can not deserialize instance of out of START_ARRAY token
 at [Source: org.apache.catalina.connector.CoyoteInputStream@1f0c4ce0; line: 1, column: 1]]}

I've just removed everything unnecessary from request body and now it works 

body = ["body": commentBody

The commentBody was defined above like 

Comment comment = commentManager.getLastComment(event.getIssue())
String commentBody = comment.getBody()  

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you