Forums

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

How to send REST call(GET,POST) in jira workflow to external server

TAMILSELVAN V June 18, 2020

Hi ,

I have a case where when transitioning from State Todo to In progress, I need to take a value of a field(e.g. ENV) and send a request(GET/POST) to server(e.g http://test:4000\). The server verify values and send a response(Success/Failure) message back to Jira.

Only when the message is success, the workflow should allow transition to move from Todo to In progress, else error message should display and stay in Same transition(i.e TODO).

Could you help me how to send a response(GET/POST) to server(http://test:4000\) and display message in JIRA?

Is it achievable through script in Workflow postfunction?

Please let me know the solution.

 

 

Regards,

Tamil

2 answers

1 accepted

0 votes
Answer accepted
Tamil June 25, 2020

Hi Mathis,

With reference to link, i have created a script to REST(GET) to url, but i couldn't get response message back from the external url.

 

Moreover i need the message from external url to be displayed on Jira screen. how to make config to bring external url response to jira screen with pop-up message or set to field?

 

import groovy.json.JsonSlurper;
import groovy.json.StreamingJsonBuilder;
//import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue
import org.apache.commons.codec.binary.Base64;
import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.ContentType.*
import groovyx.net.http.ContentType
import static groovyx.net.http.Method.*
import groovy.json.JsonSlurper
import net.sf.json.groovy.JsonSlurper
import groovy.json.JsonOutput

// Define Required Component Access

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

// Get field values

def region="CANADA";
def ccid="ZZZZZZ";
def user="abc@gmail.com"

def jsonBody = ["region": region,"ccid":ccid,"user":user ]

 


// Define Web API to post to
def baseURL = "http://test:8000/process";

// Establish Connection and post data

URL url = new URL(baseURL);
//URLConnection connection = url.openConnection();
log.error("url="+url);

HttpURLConnection connection = url.openConnection() as HttpURLConnection;
connection.requestMethod = "GET"
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, jsonBody) }
connection.connect();
log.error("URL="+url+"Status="+connection.getResponseCode() as String)
log.error("status1"+connection.getResponseMessage())
println("getResponseMessage:" + connection.getResponseMessage())

0 votes
Mathis Hellensberg
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.
June 18, 2020

Hello @TAMILSELVAN V 

Pretty sure it's doable, but I can't say I've tried it before.

This should help you: https://community.atlassian.com/t5/Adaptavist-questions/Making-a-REST-call-using-script-runner/qaq-p/576712

Suggest an answer

Log in or Sign up to answer