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 ->
log.warn(resp.status)
}
}

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 https://docs.atlassian.com/software/jira/docs/api/REST/8.5.0/?_ga=2.28212924.1450405182.1572234190-188386877.1559530511#api/2/issue-addComment I have 400 code

1 answer

1 accepted

0 votes
Answer accepted

Hi,

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"}

Hi,

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

Instead of 

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

try

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

 It works for me.

Hi Hana! Thanks for help. The error message was 

{errorMessages=[Can not deserialize instance of com.atlassian.jira.issue.fields.rest.json.beans.CommentJsonBean 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 showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

365 views 1 3
Join discussion

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