Hello,
I am trying to create rest endpoint in scriptrunner to parse incoming json (webhook from another jira)
Here is an example of incoming json:
{
"any parameter": "#009900",
"issue": "S-1",
"iconUrl": "/images/icons/priorities/lowest.png",
"name": "Fred"
}
And my rest endpoint code (there are some extra classes):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager
import com.atlassian.jira.issue.fields.rest.json.beans.JiraBaseUrls
import com.atlassian.jira.issue.fields.rest.json.beans.CommentJsonBean
import com.atlassian.jira.issue.priority.Priority
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import groovy.json.JsonBuilder
import org.codehaus.jackson.map.ObjectMapper
import groovy.json.JsonSlurper
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
doSomething(
httpMethod: "POST"
) { MultivaluedMap queryParams, String body ->
String jsonString = "body"
JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(jsonString)
String idValue = parsedJson.issue
String idValue2 = parsedJson.get("issue")
return "issue"
}
My curl:
curl -X POST -H "Content-type: text/json" --data "@priority.json" http://jira_url/rest/scriptrunner/latest/custom/doSomething
When I put my json as a file I ve got errors in the response:
{
"message": "Unable to determine the current character, it is not a string, number, array, or object\n\nThe current character read is 'b' with an int value of 98\nUnable to determine the current character, it is not a string, number, array, or object\nline number 1\nindex number 0\nbody\n^",
"stack-trace": "groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object\n\nThe current character read is 'b' with an int value of 98\nUnable to determine the current character, it is not a string, number, array, or object\nline number 1\nindex number 0\nbody\n^\n\tat org.apache.groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:202)\n\tat org.apache.groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:153)\n\tat org.apache.groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:43)\n\tat org.apache.groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:380)\n\tat org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:110)\n\tat Script234$_run_closure1.doCall(Script234.groovy:24)\n\tat com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint$_doEndpoint_closure2.doCall(UserCustomScriptEndpoint.groovy:225)\n\tat com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint$_doEndpoint_closure2.doCall(UserCustomScriptEndpoint.groovy)\n\tat com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy:345)\n\tat com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy)\n\tat com.onresolve.scriptrunner.runner.ScriptExecutionRecorder.withRecording(ScriptExecutionRecorder.groovy:13)\n\tat com.onresolve.scriptrunner.runner.ScriptExecutionRecorder$withRecording.call(Unknown Source)\n\tat com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl.execute(DiagnosticsManagerImpl.groovy:343)\n\tat com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:215)\n\tat com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.postUserEndpoint(UserCustomScriptEndpoint.groovy:123)\n",
"status-code": "INTERNAL_SERVER_ERROR"
} Can someone help me?
Thanks a lot.