Sending the value of a custom field via a REST Post request

One of the options in Jira is to create a custom field. On transitioning a task to a certain state in my workflow I want to trigger a groovy script to send the data of this custom field via a REST Post request to an external php script.

I am using the following code: 

import com.atlassian.jira.ComponentAccessor;
import groovyx.net.http.HTTPBuilder;
import static groovyx.net.http.ContentType.URLENC;

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def email = customFieldManager.getCustomFieldObjectByName('Email Adress');

// this is the check
if(issue.getCustomFieldValue(email))
{
    def http = new HTTPBuilder( 'http://www.example.com/Scripts/test.php' );
    def postBody = [username: 'bob']; // will be url-encoded
 
    http.post( path: '/', body: postBody, requestContentType: URLENC )
    {
        resp -> println "POST Success: ${resp.statusLine}";
        assert resp.statusLine.statusCode == 201;
    }
}
else
{
    //do nothing
}

The debug/output/error console lists the following errors after running the code:

Script2.groovy: 1: unable to resolve class com.atlassian.jira.ComponentAccessor
@ line 1, column 1.
   import com.atlassian.jira.ComponentAccessor;
   ^

Script2.groovy: 2: unable to resolve class groovyx.net.http.HTTPBuilder
@ line 2, column 1.
   import groovyx.net.http.HTTPBuilder;
   ^

Script2.groovy: 3: unable to resolve class groovyx.net.http.ContentType
@ line 3, column 1.
   import static groovyx.net.http.ContentType.URLENC;
   ^

3 errors

 What is going wrong while importing the dependencies?

0 answers

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

179 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you