How to send and receive details to WebService from Jira

Omprakash Thamsetty
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.
January 3, 2019

Hi,

I have a requirement to send details to another system and create the tickets there and get the response with ticket number and update in Jira. 

For this we have WebService to create the ticket, written in Java. Required to passing the parameter to create the ticket over there. They are returning the ticket number too.

Question is here. How I can configure there WebService URl and by pass the argument to create the ticket in our Jira. I needs to update the created ticket number in one of our Jira field. 

I was looking at webHook and workflow postfunction but unable to find passing the argument and getting the return results. Can anyone guide me how I can configure this.

 

Thanks,

Om

1 answer

1 vote
Omprakash Thamsetty
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.
January 11, 2019

I tried using httpbuilder and getting the results. But How I can read the each field values, which are getting response in text/xml format. Please see below code.

 

import groovyx.net.http.*
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
import groovyx.net.http.HTTPBuilder
import groovy.xml.*
import groovy.util.XmlParser
import groovy.util.XmlSlurper

    
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method

import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent

import groovy.sql.Sql
import java.sql.Connection
import java.sql.Timestamp
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface

import org.apache.log4j.Category


def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
// Set the logging level to DEBUG
log.setLevel(org.apache.log4j.Level.DEBUG);

//def String WSDL_URL = "http://URL-links"
def http = new HTTPBuilder( 'http://url-links' )
String soapEnvelope =  """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.ws.pcr.pts.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:prDetails>         
         <arg0>
            <PRNumber>12345</PRNumber>            
            <systemPassword>USERPWD</systemPassword>            
            <systemUserID>USERNAME</systemUserID>
         </arg0>
      </ser:prDetails>
   </soapenv:Body>
</soapenv:Envelope>"""


      http.request( POST ) {  
          headers."Content-Type" = "txt/xml"
             headers."Accept" = "application/soap+xml; charset=utf-8"
             headers."SOAPAction" = "getDetails"
 
           requestContentType = ContentType.XML
          body=soapEnvelope

            response.success = { resp, xml ->  
                       log.debug "${xml}"
                

               //THIS ONE NOT WORKING              
                //def xmlOutput = new XmlParser().parseText(xml)
                //def casenumber = resp.children().find({it.name()=="caseNumber"})?.text()
                //log.debug ""${casenumber}""
                 //log.debug " case number ${xmlOutput.caseNumber.toString()}"
              
            }

            response.failure = { resp, xml ->
                log.debug "fail"
                 }
        }
luka montin September 18, 2019

Thanks I was able to use your example and response back. Did you ever figure out how to use the response and store it in an issue field ? I found this article .. which I will try out soon https://dzone.com/articles/the-simple-way-to-parse-json-responses-using-groov

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

@Omprakash Thamsetty How can i parse XML output?

Suggest an answer

Log in or Sign up to answer