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
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,427 views 0 8
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