It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to send and receive details to WebService from Jira

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

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

841 views 5 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you