I've created a scriptrunner rest endpoint that will copy an issue from a JSD server to a Jira cloud instance. The post call to create the issue in Jira cloud is failing on a groovy.json.JsonException. If I use the exact same Json in a curl call to the cloud instance, it succeeds in creating the issue. Can anyone provide insight on what might be failing?
Here is the relevant endpoint code, using static strings to rule out a problem in the data read from the JSD issue. The log data follows. On the command line, the unprintable characters are all \u0000
def http = new RESTClient(JIRA_API_URL);
http.client.addRequestInterceptor(new HttpRequestInterceptor() {
void process(HttpRequest httpRequest, HttpContext httpContext) {
httpRequest.addHeader('Authorization', 'Basic 2UucmVlZEBncm91bmR0cnV0aC5jb206SDByc2VEcmF3bkJ1Z2d5')
}
})
def jq = http.request(POST, JSON) {
uri.path = '/rest/api/2/issue'
body = [
fields: [
project: [
key: "PLAC"
],
summary: "test summary",
description: "test description",
issuetype: [
name: "Bug"
]
]
]
response.success = { resp, reader ->
result = reader.txt
}
response.failure = { resp, reader ->
log.warn("Failed to query JIRA API: " + reader.text)
}
}
Scriptrunner Log info:
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:489) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:434) .
.
2019-02-07 15:17:46,732 ERROR [common.UserCustomScriptEndpoint]: ************************************************************************************* 2019-02-07 15:17:46,732 ERROR [common.UserCustomScriptEndpoint]: Script endpoint failed on method: GET copytojira groovyx.net.http.ResponseParseException: at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:495) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:434) at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:383) at groovyx.net.http.HTTPBuilder$request$2.call(Unknown Source) at Script442$_run_closure1.doCall(Script442.groovy:56) at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.doEndpoint(UserCustomScriptEndpoint.groovy:371) at com.onresolve.scriptrunner.runner.rest.common.UserCustomScriptEndpoint.getUserEndpoint(UserCustomScriptEndpoint.groovy:256) Caused by: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object The current character read is '�' with an int value of 0 Unable to determine the current character, it is not a string, number, array, or object line number 1 index number 255 ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ...............................................................................................................................................................................................................................................................^ at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:280) at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:560) at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:489) ... 9 more Start of logs truncated as they exceeded 300 lines.
Update: the call was fine. The error was my handling of the Json returned from the call.
Include the 'Accept': 'application/json' header in your POST request
restClient.post(
path: "/rest/api/3/your/api/call",
headers: [
'Authorization': "Basic ${authString}",
'Accept': 'application/json' // <- include this to avoid the error
]
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bruce,
Thanks for updating the post. However in the future, it would help our system if you posted an answer to the question instead, and then accepted that answer. That will automatically give the post the "SOLVED" prefix.
Thanks
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.