Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Make SOAP call from Jira

Ilya Stekolnikov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 27, 2022 edited

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
)
}

 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events