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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.