Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,460,023
Community Members
 
Community Events
176
Community Groups

API call in Scriptrunner

I am trying to make an API call from Script runner script consoles to fill in a field in Zabbix. Now I'm just testing, and I get this error:

groovyx.net.http.ResponseParseException: status code: 412, reason phrase: Precondition Failed 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.call(Unknown Source) at Script974.run(Script974.groovy:21) 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 org.apache.groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:202) at org.apache.groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:153) at org.apache.groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:43) at org.apache.groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:380) at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:131) 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) ... 7 more

 

The script I use:

 

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import org.apache.log4j.Logger
import org.apache.log4j.Level
import groovy.json.JsonOutput
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import groovyx.net.http.Method
import static groovyx.net.http.Method.PATCH

// def http = new HTTPBuilder('https://serviceportal.pornhub.local:443/')
def body = [ "jsonrpc": "2.0", "method": "apiinfo.version", "id": "1","auth": "null", "params": {}]
def url ="http://192.168.1.2/"
def endpoint = "/api_jsonrpc.php"
def returnResponse
def httpBuilder = new HTTPBuilder(url)

httpBuilder.request(POST, ContentType.JSON) {
headers.contentType = "ContentType: application/json"
uri.path = endpoint
body = body
response.success = { resp, JSON ->
log.warn("Successful = " + JSON)
}

response.failure = { resp, JSON ->
log.warn("Failed = " + JSON)
}
}

 

I am not very well versed in Jira and scripting, I will be very grateful for help

1 answer

0 votes

Most of this error message is about the httpbuilder not being able to parse this response into a JSON.

But the root cause of it is that you didn't receive a valid JSON from your endpoint, probably because you didn't send a valid request.

The first line gives you some clues: "412, reason phrase: Precondition Failed"

This means that the endpoint returned a status 412 error and you need to figure out what this means from zabbix and figure out what jira sent or didn't send that zabbix expected.

Try removing ContentType.JSON for testing so that you won't get automatic parsing.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events