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 static;

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

// this is the check
    def http = new HTTPBuilder( '' );
    def postBody = [username: 'bob']; // will be url-encoded path: '/', body: postBody, requestContentType: URLENC )
        resp -> println "POST Success: ${resp.statusLine}";
        assert resp.statusLine.statusCode == 201;
    //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
@ line 2, column 1.

Script2.groovy: 3: unable to resolve class
@ line 3, column 1.
   import static;

3 errors

 What is going wrong while importing the dependencies?

0 answers

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

77 views 0 5
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