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

Call external REST API from workflow transition

daniel kim Mar 02, 2017

I have in-house system which needed to be updated according to JIRA issue transit through workflows. 

I've tried below codes with scriptrunner post-function but having no luck. (getting stackoverflow error) 

If I cannot call the external REST services from JIRA, another way is to poll regularly from our in-house system. 

(or JIRA creates JSON file then process it via batch process?) 

Any help will be appreciated. 

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 org.apache.commons.codec.binary.Base64;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issue = issue as Issue
def issueStatus = issue.status;
// find custom fields
def cf2 = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Original Call Log ID'};
def issueCalllog = issue.getCustomFieldValue(cf2);
 
def body_req = [
    "record.char_20": issueStatus,
    "record.char_21": issueCalllog
]
 
def baseURL = "http://rd0013:daniel12@192.168.170.179/IBSDevREST/rest/resources/MAIN/GE/LOG/record/17020013";
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();

 

 

 

2 answers

1 accepted

1 vote
Answer accepted
Niclas Sandstroem Mar 02, 2017

Hi I would not recommend to go down this part. Look at setting up a JIRA webhook instead that send POST to your in-house system and do GET on what you need from JIRA when this occur.

Good luck!

daniel kim Mar 05, 2017

thanks for advice.

trialled PoC on this approach and seems to be working.

 

Niclas Sandstroem Mar 05, 2017

Your welcome! Happy to share insights smile

 

vaishal Jun 09, 2017

Hi Niclas,

My task is like create Index on Elasticsearch whenever Ticket is created in Jira.

To create Index in Elasticsearch we need to pass some JSON which contains static JSON. but not related to JIRA ticket.

Is Weebhook pass JSON for me?

Niclas Sandstroem Jun 09, 2017

You can't get JIRA to send a custom JSON so this is not possible. You can track https://jira.atlassian.com/browse/JRASERVER-63205

You could see if any plugin enables this or just let middleware receive the push from JIRA and let that do what you need in Elasticsearch.

Good luck!

vaishal Jun 09, 2017

Thanks Niclas for quick reply

Can i post custom JSON data from groovy script written in post function?

Niclas Sandstroem Jun 11, 2017

vaishal please check Thanos answer below...

0 votes
Thanos Batagiannis [Adaptavist] Community Leader Mar 03, 2017

Hi Daniel,

I suppose you can try to use the groovyx.net.http.RESTClient. Have a look at Jamie's asnswer

https://answers.atlassian.com/questions/33129265

The above example makes a call to an external JIRA instance, but you can modify it. Hope that helps.

regards, Thanos

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

1,090 views 13 15
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