REST Calls with Issue Events

With Easy Integration's Issue Listeners, you can integrate your Jira with your internal/external systems by calling REST services accordingly. On this page, you will find out how to define a listener and configure the REST service.

Listeners can be accessed within Easy Integration's admin UI (Jira admin cog icon > Manage apps > Easy Integrations Menu > Listeners (EI)).  

The above page shows all the listeners that you have already defined. You can also:

  1. Create a new listener.
  2. Edit an existing listener.
  3. Delete an existing listener.

To Create a New Listener

  1. Click on the Add New Listener button.
  2. Fill in the information about the listener.

  1. Create a name for the listener.
  2. Select projects that you want to listen out for issue events and call REST services. You can also choose the All Projects option.
  3. Similarly, select issue types. You can also choose the All Issue Types option.
  4. Select the issue event(s) which you want to listen to. You can select multiple issue events.

Script for Execution

In this part, you can add a condition for the listener. 

By default, it only has the return true statement which means that the listener will execute the REST call. However, you can type your own script in order to programmatically add a condition to execute the REST service or not.

Below is a sample code snippet for a condition that checks the logged-in user should be the reporter of the issue:

Execute Code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser"current user:" + currentUser.username)
def reporter = issue.reporter.username"reporter: " + reporter)
return reporter.equals(currentUser.username)

REST Service Details

In this part, REST details (URL, method, headers, body, credential, etc) are created.

  1. The endpoint of the REST service. You can type any dynamic parameter here using double curly braces. (e.g.{{bookId}} assuming bookId is defined within the Parameters section which is described below.
  2. Select the Http Method (GET, POST, PUT, DELETE).
  3. Define your HTTP header key/value sets in separate lines (as shown in the screenshot).
  4. Type the JSON request body - you can use dynamic parameters here as well.
  5. Define all your dynamic parameters here. You can add static values as well as the dynamic values of fields/custom fields in the Jira issue. Below are some sample usages.
  6. Choose the authorization type. Currently, BASIC Authentication is supported. If you choose the Basic Authorization Type, the credential will become active and the credentials you defined in the Credentials section will be listed.

Headers code example:


Request body code example:

Request Body
   "item"  : "{{productName}}",
   "price" : "{{price}}",
   "date"  : "{{date}}",
   "item"  : "{{productName}}",
   "owner" : "{{user.displayName}}"

Parameters code example:

assignee    = $issue.assignee or {{issue.assignee}}
reporter    = {{issue.reporter}}
date        = $issue.created
formattedDate = $DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format($issue.created)
productName = $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_11100'))
price       = $issue.getCustomFieldValue($customFieldManager.getCustomFieldObject('customfield_11102'))
displayName = $user.displayName
userDisplayName = $ComponentAccessor.getUserManager().getUserByName("someUser").getDisplayName() // you can also use ComponentAccessor
comment     = $comment // this is the comment that is passed through the transition

For more details on parameter assigning and utils, see the Parameters Usage Examples page.
Also see ComponentAccessorUserIssue and Status API for all properties and methods.

Run asynchronously?

In this section, you can enable async to execute the REST service asynchronously. There are a couple of reasons why you may want to execute asynchronously.

  1. Executing synchronously makes the user wait for the transition for longer than usual. If the host of the REST service responds late or there is a connection time out between the Jira server and the host, the user will wait for the spinner for a long time. So, it may be wise to enable async if your REST service responds slowly.

  2. Some issue parameters may wait for calculation or reindexing. Some plugins may work in the background to populate the actual result of a custom field and you may want to use that value. 

There is a scheduled task named Easy Integrations for Jira - Async Rest Caller Sched.

Post Operations

In this section, you will find out how to update a custom field based on a value in the REST response.

  1. First, tick the Update custom field checkbox.
  2. Select the custom field that you want to update from the drop-down menu.
  3. Type the jsonpath accordingly to select the value. If the result is not JSON and you want to update a custom field with the body itself, just leave this textbox empty.

See the jsonpath examples page for jsonpath samples.