Trying to validate the groovy script created for Rest API response

Sekhar Chandra January 23, 2020

Hi All,

We need to create a scripted in Jira that is able to check the API response and compare a specific value in the response against the value submitted by the customer in the field.

Say, API_var1=Custome_field_var2, customer submitted value is correct and allow submission of ticket, if they are not equal then return an error with " response is wrong".

 

I some how generated the code with "postman" for POST request and body for parameters but stuck at how to configure the fields to be get compared and get the response on the ticket.

Here I attach my code for reference, please help me out of this.

Thanks.

 

-------------------------------------------------------------------------------------------

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import com.atlassian.jira.component.ComponentAccessor;
def http = new HTTPBuilder('https://postman-echo.com/post')
//http.auth.basic('username','password')

http.request(POST){
requestContentType = ContentType.JSON
body = [foo1: 'bar1', foo2: 'bar2']

response.success = {resp,JSON->return "POST Success ${resp.statusLine} ${JSON}"
}

response.failure = {resp->return"Resquest failed with status ${resp.status}"
}
}

 

----------------------------------------------------------------------------------------------

 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events