Skip to end of banner
Go to start of banner

REST Calls With Issue Events

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

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

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


 On this page, you can find all listeners that you already defined. Also you can;

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

To create a new listener

  1. Click Add New Listener button
  2. Fill information regarding the listener
















  • Give a name to the listener.
  • Select projects which you want to listen issue events and call REST services. You can also choose the All Projects option.
  • Similarly, select issue types. You can also choose the All  Issue Types option.
  • Select the issue event(s) which you want to listen. You can select multiple issue events.

Script for execution

In this section, you can give a decision to execute REST according to the result of the Groovy script.
By default, it has only return true statement. However, you can type your script and return true; to execute REST, or return false; not to execute


Below, there is a sample code on how you can type your own script.

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

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


REST Service Details

In this section, REST details (URL, method, headers, body, credential, ..) are filled.

  1.  The endpoint of the REST service. You can type any dynamic parameter here using double curly braces. (e.g. http://mycompany.com/api/book/{{bookId}} assuming bookId is defined in 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 described in screen-shot
  4. Type 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. Here are some sample usages:
  6.  Choose the authorization type. Currently, BASIC Authentication is supported.  If you choose Basic Authorization Type, credential becomes active, and the credentials you defined in the Credentials section are listed.

Headers code example;

Headers
Accept=application/json

Request body code example;

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


Parameters code example;

Parameters
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 and utils for parameter assigning see Parameters usage examples 
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 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 users wait for the spinner a lot. So, it may be wise to enable async if your REST service responds slow

  2. Some issue parameters may wait for calculation or reindexing. Some plugins may work 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 can configure to update a custom field based on a value in the REST response

  • First click on Update custom field checkbox
  • Custom field drop-down is displayed, select the one you want to update
  • Type 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.

  1. Click the checkbox if you want to update any custom field
  2. A select custom field which will be update
  3. Type jsonpath for custom field

See jsonpath examples page for jsonpath samples.

  • No labels