Configuring And Integrating Jira & Webhooks In Mule 4

Author: Ritika Salaria

This blog serves as a guide on how to configure and integrate Jira with your application in Mule 4. We will cover the process of creating Jira issues, assigning them to specific users, and adding watchers. Additionally, we will delve into the configuration of Jira webhooks.

About Jira
  • Jira is a proprietary issue-tracking product developed by Atlassian, which enables bug tracking and agile project management.
  • Developers can plan new features to be added and bugs to be fixed in the upcoming release.
Prerequisites:
  • An Atlassian account and admin access to Jira Software.
  • An API token in Jira is utilized for performing basic authentication with Jira Cloud applications or Atlassian Cloud. You can create an API token in the Security settings of your account using any label name.
    curl --request GET \
      --url 'https://your-domain.atlassian.net/rest/api/3/issue/createmeta' \
      --user 'email@example.com:<api_token>' \
      --header 'Accept: application/json'

    Note: For each domain, the issue ID may vary from project to project, even for similar issue types.

    Steps:
    1. To begin, we need to include the Jira dependency in our Anypoint Studio project. Search in Exchange for the Jira Connector and download the latest version of it.
    1. Now that you have added the Jira dependency and fetched the details for the issue, such as issueType and its ID (here, we will be creating a task and a subtask) using the prerequisites steps, create a Mule flow using a listener, transform message, and the ‘create issue’ component.
    1. Create a Jira configuration with the connection set to Basic Auth and add the required details, along with the API token created earlier.

    The baseUri should look something like this: https://your-domain.atlassian.net/

    1. Create the task JSON body in the transform message as follows:
    {
      "fields": {
        "assignee": {
          "id":  "5b109f2e9729b51b54dc274d"
        },
    	"summary":   "mule_test issue",
        "description": {
          "content": [
            {
              "content": [
                {
                  "text": "Creating this issue to test Jira connectivity. Test issue",
                  "type": "text"
                }
              ],
              "type": "paragraph"
            }
          ],
          "type": "doc",
          "version": 1
        },    
        "issuetype": {
          "name": "Task",
          "id":  "100"
        },
        "project": {
          "key":  "TEST"
        },
        "reporter": {
          "id":  "5b109f2e9729b51b54dc274d"
        }
      },
      "update": {}
    }

    Note: Please ensure to edit the values for the assignee ID, reporter ID, issuetype ID, issuetype name, and the project key with the ones you require. Here, we are creating an issue of type “TASK”.

    Furthermore, to set yourself as an assignee or reporter, you can obtain your ID from the URL in the Jira profile settings.

    1. After running the Mule app, you should be able to successfully create an issue, with the response payload containing the unique Jira issue ID. You can also locate it in the Jira UI, along with the expected input payload.
    2. Now, to create a subtask linked to the aforementioned task, you need to set the issue type to ‘subtask’ with its issue ID, and add the parent JSON object to the existing input payload as shown below:
    {
      "fields": {
        "assignee": {
          "id":  "5b109f2e9729b51b54dc274d"
        },
    	"summary":   "mule_test issue",
        "description": {
          "content": [
            {
              "content": [
                {
                  "text": "Creating this issue to test Jira connectivity. Test issue",
                  "type": "text"
                }
              ],
              "type": "paragraph"
            }
          ],
          "type": "doc",
          "version": 1
        },    
        "issuetype": {
          "name": "Subtask",
          "id":  "10"
        },
        "project": {
          "key":  "TEST"
        },
    "parent": {
          "key":  "TEST-2"
         },
        "reporter": {
          "id":  "5b109f2e9729b51b54dc274d"
        }
      },
      "update": {}
    }

    The parent key will be the issue ID for the task we created in the previous step.

    1. To add a watcher for your created Jira issues, drag and drop the ‘Add Watcher’ component. Enter the issue ID along with the Jira user ID of the desired watcher as payload.

    Note: The Add Watcher component or Jira REST API does not have a provision to add multiple watchers at once, right now. To combat this, you can use the For Each block.

    Creating Jira Webhook
    1. To connect to Jira via a webhook, open the Jira project you are working with and navigate to project settings. Under the Automation option on the left, click on ‘Create a rule’.
    1. Select the trigger for your webhook. In this case, we will be using the ‘Field Value Changed’ option. This webhook will listen to any status change whenever someone edits an issue.
    1. Save the created rule and click on ‘Add Component’. Under ‘New Action’, select ‘Send Web Request’. Add the request URL and customize the request body in JSON format according to your requirements. The key-value pairs will fetch only the necessary details about the Jira issue and include them in the request body.

    Note: If your Mule API utilizes client ID enforcement or any other authentication policy, you can also add headers in this section.

    1. Save the component and name your newly created automation in the next step. Activate the rule, and you should be able to see it in the automation rules now.
    1. Now, as long as your application is running on the Anypoint Platform, the created webhook will call your API and perform the necessary actions.
    References:

    For more information on performing various Jira operations, please refer to the Jira REST API documentation.

    https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/#about

    We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.