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

Calling REST Api from within script-runner post-function (and needed libraries)

Bryan Karsh Jun 06, 2013

I couldn't edit my original question to be more clear, so I am rewording it as a new question.

I am experimenting with script runner in a post function in one of my projects. I want to get a dump of all fields of theissue , which I can then pass to an external too for some processing.

I know I can do something like this:

def curl = "/usr/bin/curl -u foo:bar"

def output = curl.execute().text

This does give me a variable ($output) containing populated fields for the issue that I can plug into a bash script I have on the server for parsing, etc.

However, I am trying to see if I can do something similar from straight within groovy, without a call to some external tool.

Any advice? I am a groovy noob, so if you have any examples, please let me know. I have some examples online, but they seem to call libraries that I don't have (guessing they were written for stand alone groovy, and not script runner..?)

4 answers

1 accepted

0 votes
Bryan Karsh Jun 10, 2013

There is probably a better way to go about this, but I ended up doing the folowing to get system and custom field data:

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.issue.Issue;

// gets a reference to the IssueManager and CustomFieldManager manager classes
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
// gets a reference to the desired issue and custom field
Issue issue = issueManager.getIssueObject( "FOOBAR-100" );

def cflist = customFieldManager.getCustomFieldObjects(issue);

def map = new HashMap<String,String>()

cflist.each {cf ->
Object value = issue.getCustomFieldValue(cf)
    map << [(cf):"$value"]


def systemfields = issueManager.getIssue ("FOOBAR-100")  //getting GenericObject since it seems to contain issue fields

map << systemfields   // left-shift systemfields map into map to create consolidated map

//Example showing line by line output:
map.each{ k, v -> println "${k}::${v}" }

0 votes

do you have any idea why this is not working with -X PUT? GET is working fine...

def curl = "/usr/bin/curl -u FECRU_CREDENTIALS -H Content-Type:application/json -H Accept:application/json -X PUT -d FECRU_DATA FECRU_REST_API"

0 votes
Rama Krishna Jul 28, 2015

Can any one show how to send post request with data to JIRA to update or insert issue from Java client.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted in Statuspage

⭐️Would you recommend Statuspage? Leave a (honest!) review. ⭐️

Hi Community friends, We're working on sourcing more reviews on Capterra – a popular software review site –  to help teams like yours make more informed decisions when choosing an inc...

77 views 3 5
Join discussion

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