---
title: "REST calls with issue events"
canonical: "https://support.appfire.com/space/EI4J/11206987/REST%20calls%20with%20issue%20events"
format: markdown
---
> Macro (aura-html)

This guide explains how to configure Easy Integration's **Issue Listeners** to call external REST services when specific issue events occur in your Jira projects. By following these steps, you can integrate your internal and external systems to automate workflows and improve data exchange.

## Accessing listeners

<span style="color: #000000">Listeners can be accessed within Easy Integration's admin UI (</span><span style="color: #000000">**Jira admin cog icon > Manage apps > Easy Integrations Menu > **</span><span style="color: #000000">**Listeners (EI)**</span><span style="color: #000000">).  </span>

![image](media://565f0100-2746-41d0-8cbc-2cf21fe3261b)

This page displays all existing listeners. You can perform the following actions:

1. <span style="color: #000000">**Create**</span><span style="color: #000000"> a new listener.</span>
2. <span style="color: #000000">**Edit**</span><span style="color: #000000"> an existing listener.</span>
3. <span style="color: #000000">**Delete**</span><span style="color: #000000"> an existing listener.</span>

---

## Step 1: Create a new listener

1. <span style="color: #000000">Click the </span><span style="color: #000000">**Add New Listener**</span><span style="color: #000000"> button.</span>
2. Fill in the listener details:
  - **Name:** Assign a descriptive name for your listener.
  - **Projects:** Select the specific projects where you want to monitor issue events. You can also choose `All Projects`.
  - **Issue Types:** Select the issue types you want to listen to, or choose `All Issue Types`.
  - **Issue Events:** Select one or more issue events that trigger the listener.

## Step 2: Add a condition

<span style="color: #000000">In this part, you can add a condition for the listener. </span>

![image-20240814-115112.png](media://681e6e31-0934-4418-9a11-8cece1ba0907)

<span style="color: #000000">By default, it only has the </span><span style="color: #000000">**return true**</span><span style="color: #000000"> statement, which means that the listener will execute the REST call. However, you can type your own script to programmatically add a condition to execute the REST service or not.</span>

<span style="color: #000000">Below is a sample code snippet for a condition that checks the logged-in user should be the reporter of the issue:</span>

**Execute Code**

```groovy
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)
```

## Step 3: Fill in REST service details

<span style="color: #000000">In this part, REST details (URL, method, headers, body, credential, etc.) are created.</span>

1. <span style="color: #000000">**URL – **</span><span style="color: #000000">The endpoint of the REST service. You can type any dynamic parameter here using double curly braces. (for example, </span>`http://mycompany.com/api/book/{{bookId}}`<span style="color: #000000"> assuming bookId is defined within the Parameters section which is described below.</span>
2. <span style="color: #000000">**Method –**</span><span style="color: #000000"> Select the HTTP Method (GET, POST, PUT, DELETE).</span>
3. <span style="color: #000000">**Headers –**</span><span style="color: #000000"> Define your HTTP header key/value sets in separate lines.</span>
4. <span style="color: #000000">**Request Body –**</span><span style="color: #000000"> Type the JSON request body—you can use dynamic parameters here as well. Note that if send attachments is selected, the request body must be in a form-data format where key-value pairs can be defined. Check the code block below:</span>
5. <span style="color: #000000">**Parameters –**</span><span style="color: #000000"> Define all your dynamic parameters. You can add static values as well as the dynamic values of fields/custom fields in the Jira issue. Below are some sample usages.</span>
6. <span style="color: #000000">Choose the authorization type. Currently, BASIC Authentication is supported. If you choose the </span><span style="color: #000000">**Basic**</span><span style="color: #000000"> Authorization Type, the credential will become active and the credentials you defined in the </span>[Credentials](https://confluence.snapbytes.com/display/EI4J/Credentials) <span style="color: #000000">section will be listed.</span>

<span style="color: #000000">Headers code example:</span>

**Headers**

```
Accept=application/json
```

<span style="color: #000000">Request Body code example:</span>

**Request Body**

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

<span style="color: #000000">Parameters code example:</span>

**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
```

<span style="color: #000000">For more details on parameter assigning and utils, see the</span> [Parameters Usage Examples](https://confluence.snapbytes.com/display/EI4J/Parameters+usage+examples) <span style="color: #000000">page.</span>  
<span style="color: #000000">Also, see </span>[ComponentAccessor](https://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/component/ComponentAccessor.html), [User](https://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/user/ApplicationUser.html), [Issue](https://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/issue/Issue.html), <span style="color: #000000">and</span> [Status](https://docs.atlassian.com/software/jira/docs/api/latest/com/atlassian/jira/issue/status/Status.html) <span style="color: #000000">API for all properties and methods.</span>

## Step 4: Run asynchronously (Optional)

<span style="color: #000000">In this section, you can enable </span><span style="color: #000000">**Async**</span><span style="color: #000000"> to execute the REST service asynchronously. There are a couple of reasons why you may want to execute asynchronously.</span>

![Screenshot 2024-08-14 at 15.00.22.png](media://06ef188b-de58-4efe-9bd8-5861142c82f5)

- <span style="color: #000000">Executing synchronously makes the user wait for the transition longer than usual. If the REST service host responds late or there is a connection timeout 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.</span>
- <span style="color: #000000">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. </span>

<span style="color: #000000">There is a scheduled task named </span><span style="color: #000000">**Easy Integrations for Jira - Async Rest Caller Sched**</span><span style="color: #000000">.</span>

## Step 5: Update custom field (Optional)

<span style="color: #000000">In this section, you will find out how to update a custom field based on a value in the REST response.</span>

![Screenshot 2024-08-14 at 15.02.23.png](media://360ec1d9-0afc-460b-a9a9-e6618f585612)

1. <span style="color: #000000">First, tick the </span><span style="color: #000000">**Update**</span><span style="color: #000000"> </span><span style="color: #000000">**custom field**</span><span style="color: #000000"> checkbox.</span>
2. <span style="color: #000000">Select the custom field that you want to update from the drop-down menu.</span>
3. <span style="color: #000000">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.</span>

<span style="color: #000000">See the</span> [JSONPath examples](https://confluence.snapbytes.com/display/EI4J/jsonpath+examples) <span style="color: #000000">page for samples.</span>

## Step 5: Send attachments

<span style="color: #000000">In this section, you will find out how to send attachments with REST calls.</span>

![Screenshot 2024-08-14 at 15.03.53.png](media://e41e348f-67c9-404f-89a7-3e5e527d51c7)

1. <span style="color: #000000">First, tick the </span><span style="color: #000000">**Send Attachments**</span><span style="color: #000000"> checkbox.</span>
2. <span style="color: #000000">Write the name of the form-data parameter name that contains attachments. For instance, in Jira REST API for attachments, this name must be </span>`file`,<span style="color: #333333"> and in ServiceNow REST API, this name must be </span>`uploadFile`<span style="color: #293e40">.</span>
3. <span style="color: #000000">Write a groovy script that returns attachments. These attachments will be sent with the REST call. If the script is empty, then all attachments will be sent.</span>

**Send Attachments**

```groovy
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.AttachmentManager;

AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager();
def attachments = attachmentManager.getAttachments(issue);
return attachments;
```