Hi,
I've been doing some integration with JIRA and ServiceNow and was using an JIRA cloud dev environment for my initial testing where everything was working great.
I have now transitioned to a local server version of JIRA and it seems like the Unirest.post function is not defined by default in this version. I was wondering if there is an import I can make to get it to work or if I need to use a different method.
def statusresponse = Unirest.post("https://xxxxx.service-now.com/api/now/table/change_request")
.basicAuth("xxxx", "xxxxx")
.header("Accept","application/json")
.header("Content-Type","application/json")
.body("{\"u_subcategory\":\""+iss+"\",\"category\":\"Jira Integration\",\"short_description\":\""+desc+"\",\"correlation_id\":\""+key+"\",\"correlation_display\":\"Jira Integration\"}")
.asJson();
This is the code that was working on the cloud version but now gives an error in the server version.
Hello,
Kindly have a look at this link (there is an example of how you can do it)
Using that method and I'm able to send the POST request. But with Unirest after running the Unirest.post function it returns the body of the response :
POST https://devxxxx.service-now.com/api/now/table/change_request asJson Request Duration: 4422ms status: 201 - Created body: {"result":{"parent":"","made_sla":"true","caused_by":"",....}}
I seem to be unable to retrieve the response body using HttpURLConnection
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think connection.getResponseMessage() should get the response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
connection.getResponseMessage() was returning sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@69c728b9
I had to buffer the input stream to read it properly:
def inputStream = connection.getInputStream();
BufferedReader input = new BufferedReader(
new InputStreamReader(
inputStream));
StringBuilder response = new StringBuilder();
String currentLine;
while ((currentLine = input.readLine()) != null)
response.append(currentLine);
input.close();
response.toString();
This gave me the same output as using Unirest.
Thanks for the help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure why Unirest is not working in ScriptRunner. I tried everything and searched a lot but I couldn't get it to work.
BufferedReader & StringBuilder would also work but it looked to complicated.
But parsing the inputStream with Groovy JsonSlurper is working for me. Like in the snippet below:
import groovy.json.JsonSlurper;
// ... code from the example
InputStream inputStream = connection.getInputStream();
def json = new groovy.json.JsonSlurper().parse(inputStream);
log.info(json.getAt(0));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use
@Grapes(
@Grab(group='com.mashape.unirest', module='unirest-java', version='1.4.9')
)
import com.mashape.unirest.http.Unirest
Unirest.get("<URL>")
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.