REST POST call to external application in Jira workflow postfunction

Tamil June 22, 2020

Hi,

 

I have project where when workflow transition moves from TODO to IN PROGRESS, i need to send custom field values to external url for validation. i havet ried groovy script using REST API in workflow postfunction where i am trying to pass value but i am getting error.

The response from the REST API should shown in jira screen. how can i make it happen?

 

I am new to groovy scripting and can someone help with restructuring the code

 

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;

 


def region="CANADA"
def id="121190"
def email="email_id@gmail.com"

 


def body_req = [
"region":region,
"ccid":id,
"email":email

]

def baseURL = "http://local-url:1000/process";

URL url;

url = new URL(baseURL);

URLConnection connection = url.openConnection();
connection.requestMethod = "POST"
connection.doOutput = true
connection.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection.outputStream.withWriter("UTF-8") { new StreamingJsonBuilder(it, body_req) }
connection.connect();


println("url: " + url);
println("Content:" + connection.getContent())
println("ResponseCode:" + connection.getResponseCode())
println("getResponseMessage:" + connection.getResponseMessage())

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events