I need to make something like
curl --header "Content-Type: text/xml; charset=utf-8" -d "<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:jira="Jira"><soap:Header/><soap:Body><jira:ChekBin><jira:data>{"data":"090940004546"}</jira:data></jira:ChekBin></soap:Body></soap:Envelope>" "http://10.11.10.33/KB/ws/Jira.1cws?wsdl" -u "11111:22222"
how can i do this with scriptrunner?
my code is
import groovy.json.JsonOutput
import groovyx.net.http.ContentType
import groovyx.net.http.HttpResponseDecorator
import groovyx.net.http.RESTClient
import com.atlassian.jira.component.ComponentAccessor
final externalUrl = "URL HERE"
def BINField = ComponentAccessor.customFieldManager.getCustomFieldObject(15600) //Custom Field: BIN
String BINFieldVal = issue.getCustomFieldValue(BINField)
log.debug ("Bin Field is := " + BINFieldVal)
if (BINFieldVal == null){
return false
}
def body = JsonOutput.toJson([data: BINFieldVal])
def postResponse = post(externalUrl, "post", "", body)
if (postResponse) {
def responseGetMap = postResponse as Map
responseGetMap.eachWithIndex { key, val, index ->
println "$index Hex Code: $key = Color Name: $val"
log.debug("INDEX $index KEY $key VAL: $val")
log.debug (responseGetMap.get('bin'))
}
def bin = responseGetMap.get('bin') as boolean
if (bin) {
log.debug ("The bin is: " + bin)
if (bin == true) {
return true
} else if (bin == false) {
return false
}
} else {
log.debug ("The bin is null: " + bin)
return false
}
}
def post(def hostUrl, def endpoint, def query, def bodyJson) {
def client = new RESTClient(hostUrl)
client.setHeaders([
'Accept' : ContentType.JSON,
// If authentication mechanism of the API requires a special header, it can be added here
'x-api-key': '<YOUR KEY>'
])
client.handler.success = { HttpResponseDecorator response, json ->
json
}
client.handler.failure = { HttpResponseDecorator response ->
// Failure can be handled here
if (response.getStatus() == 403) {
log.error ("Forbiden: Status code " + response.getStatus())
log.error response.entity.content.text
} else if (response.getStatus() == 500){
log.error ("Server Internal Prolem: Status code " + response.getStatus())
log.error response.entity.content.text
}
return false
[:]
}
client.post(
path: endpoint,
queryString: query,
contentType: ContentType.JSON,
body: bodyJson
)
}
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.