{
  "id": "pZwQxc7aYCJli9In",
  "name": "My workflow 6",
  "tags": [],
  "nodes": [
    {
      "id": "9852ca3e-4cf9-4976-8399-e794574ee7fd",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1936,
        144
      ],
      "parameters": {
        "width": 784,
        "height": 560,
        "content": "## Automatically Assign Jira Reporter from Forwarded Email Body\n\nThis workflow automates the process of correctly assigning the 'Reporter' for Jira Service Management tickets that are created from forwarded emails. When an email is forwarded to your support address, Jira often sets the forwarding system as the Reporter. This template solves this issue by parsing the email body to set the original sender as the Reporter.\n\n---\n\n### \ud83d\ude80 How it Works\n1.  **New Ticket Trigger**: The workflow starts whenever a new Jira ticket is created.\n2.  **Email Filter**: It checks if the ticket was created by one of your specified forwarding email addresses.\n3.  **Parse Details**: It extracts the original sender's name and email address from the ticket's description.\n4.  **Search for Customer**: It uses the extracted email to look up the existing customer in Jira.\n5.  **Update or Create**:\n    - If the customer exists, it updates the ticket's 'Reporter' field.\n    - If the customer doesn't exist, it first creates a new customer and then updates the ticket.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "31b7529d-19aa-43d7-bebd-c16d25d83415",
      "name": "Filter Forwarding Emails",
      "type": "n8n-nodes-base.if",
      "position": [
        -1456,
        864
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "f1a6f3aa-5e68-466b-8ebd-6b30b5624a2e",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.user.displayName }}",
              "rightValue": "user@example.com"
            },
            {
              "id": "6593b724-da0a-4077-9682-a2335498bf5c",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.user.displayName }}",
              "rightValue": "user@example.com"
            },
            {
              "id": "8062e93d-a37f-4d39-b8e6-f57e846ad65d",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.user.displayName }}",
              "rightValue": "user@example.com"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "4c875368-9718-4929-9921-31ad9f1b9d4e",
      "name": "Set Description Variable",
      "type": "n8n-nodes-base.set",
      "position": [
        -1232,
        784
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e9f0d4c3-b15f-4553-9c98-74fc97e9bfe1",
              "name": "description",
              "type": "string",
              "value": "={{ $json.issue.fields.description }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "01673b59-29a4-49ec-b036-87705836261d",
      "name": "Parse Details From Description",
      "type": "n8n-nodes-base.code",
      "position": [
        -992,
        768
      ],
      "parameters": {
        "jsCode": "// This array will hold the final output items\nconst outputItems = [];\n\n// Loop through each item provided to the node\nfor (const item of items) {\n  // Get the description string from the input JSON\n  const description = item.json.description;\n\n  // Initialize variables to store the results\n  let name = null;\n  let email = null;\n  let websiteUrl = null;\n\n  // --- ATTEMPT 1: Parse for labeled data (e.g., \"Name: ...\") ---\n  const nameMatch = description.match(/name:\\s*(.*)/i);\n  if (nameMatch && nameMatch[1]) {\n    name = nameMatch[1].trim();\n  }\n\n  const emailMatch = description.match(/email:\\s*\\[?([\\w\\.\\-]+@[\\w\\.\\-]+\\.\\w+)/i);\n  if (emailMatch && emailMatch[1]) {\n    email = emailMatch[1].trim();\n  }\n\n  // --- ATTEMPT 2: If no email found, parse for \"From:\" line in forwarded emails ---\n  if (!email) {\n    // This regex captures the name and the email from a line like \"From: John Doe <user@example.com>\"\n    const fromMatch = description.match(/From:\\s*(.*?)\\s*<([\\w\\.\\-]+@[\\w\\.\\-]+\\.\\w+)>/i);\n    if (fromMatch && fromMatch.length === 3) {\n      // If a match is found, fromMatch[1] is the name and fromMatch[2] is the email\n      name = fromMatch[1].trim();\n      email = fromMatch[2].trim();\n    }\n  }\n\n  // --- Parse Website URL (with a fallback) ---\n  // First, look for a labeled URL\n  const websiteMatchLabeled = description.match(/website url:\\s*(https?:\\/\\/[^\\s]+)/i);\n  if (websiteMatchLabeled && websiteMatchLabeled[1]) {\n    websiteUrl = websiteMatchLabeled[1].trim();\n  } else {\n    // If a labeled URL isn't found, look for the first URL in Jira's link format\n    const websiteMatchGeneric = description.match(/\\[(https?:\\/\\/[^\\s|\\]]+)/i);\n    if (websiteMatchGeneric && websiteMatchGeneric[1]) {\n      websiteUrl = websiteMatchGeneric[1].trim();\n    }\n  }\n\n  // Construct the new item with the extracted data\n  const newItem = {\n    json: {\n      name: name,\n      email: email,\n      websiteUrl: websiteUrl\n    }\n  };\n\n  // Add the newly created item to our output array\n  outputItems.push(newItem);\n}\n\n// Return all the processed items\nreturn outputItems;"
      },
      "typeVersion": 2
    },
    {
      "id": "acf52eaf-fe80-4a45-aadb-3ba4be7d7c59",
      "name": "Update Reporter (New Customer)",
      "type": "n8n-nodes-base.jira",
      "position": [
        48,
        816
      ],
      "parameters": {
        "issueKey": "={{ $('Jira Trigger1').item.json.issue.key }}",
        "operation": "update",
        "updateFields": {
          "reporter": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $json.accountId }}"
          }
        }
      },
      "typeVersion": 1
    },
    {
      "id": "7b2d59d9-cadc-4a07-8c4c-2038717f65cd",
      "name": "Search for Existing Customer",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        -688,
        688
      ],
      "parameters": {
        "url": "=https://YOUR_JIRA_DOMAIN.atlassian.net/rest/servicedeskapi/servicedesk/{{ $('Jira Trigger1').item.json.issue.fields.project.key }}/customer",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "query",
              "value": "={{ $json.email }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "X-ExperimentalApi",
              "value": "optin"
            }
          ]
        },
        "nodeCredentialType": "jiraSoftwareCloudApi"
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "f2c0d12c-be9c-4521-ae03-69a4a85d7bb2",
      "name": "If Customer Exists",
      "type": "n8n-nodes-base.if",
      "position": [
        -480,
        688
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "48715483-0caa-49c8-ad08-fd77ad30c2e1",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.values[0].active }}",
              "rightValue": "true"
            }
          ]
        },
        "looseTypeValidation": "="
      },
      "typeVersion": 2.2
    },
    {
      "id": "dd5156c4-a9b9-4e99-b75f-60fdea68a869",
      "name": "Update Reporter (Existing Customer)",
      "type": "n8n-nodes-base.jira",
      "position": [
        -160,
        592
      ],
      "parameters": {
        "issueKey": "={{ $('Jira Trigger1').item.json.issue.key }}",
        "operation": "update",
        "updateFields": {
          "reporter": {
            "__rl": true,
            "mode": "id",
            "value": "={{ $json.values[0].accountId }}"
          }
        }
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d120a4dc-8ab7-4f54-a361-a1d65381c69e",
      "name": "Jira Trigger1",
      "type": "n8n-nodes-base.jiraTrigger",
      "position": [
        -1680,
        864
      ],
      "parameters": {
        "events": [
          "jira:issue_created"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "253569a7-8916-4d24-8566-8114fa080593",
      "name": "Create Customer1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -208,
        832
      ],
      "parameters": {
        "url": "https://YOUR_JIRA_DOMAIN.atlassian.net/rest/servicedeskapi/customer",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendHeaders": true,
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "displayName",
              "value": "={{ $('Parse Details From Description').item.json.name }}"
            },
            {
              "name": "email",
              "value": "={{ $('Parse Details From Description').item.json.email }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            }
          ]
        },
        "nodeCredentialType": "jiraSoftwareCloudApi"
      },
      "typeVersion": 4.2
    },
    {
      "id": "fb216c19-b207-42ab-8f1f-79719fd174a0",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1104,
        144
      ],
      "parameters": {
        "width": 576,
        "height": 464,
        "content": "---\n\n### \ud83d\udee0\ufe0f Setup Instructions\n\nFollow these steps to configure and use this workflow:\n\n1.  **Set Jira Credentials**: In the **Jira Trigger**, **Jira Software**, and **HTTP Request** nodes, select your Jira Software Cloud API credentials.\n2.  **Select Trigger Project**: In the **Jira Trigger** node, choose the project(s) you want to monitor.\n3.  **Update Email Addresses**: In the first **If** node (\"Filter Forwarding Emails\"), replace the example emails (`your-address-1@example.com`, etc.) with your actual forwarding email addresses.\n4.  **Update Jira Domain**: In both **HTTP Request** nodes (\"Search for Existing Customer\" and \"Create Customer\"), replace `YOUR_JIRA_DOMAIN` with your actual Atlassian domain (e.g., `mycompany.atlassian.net`).\n5.  **Activate Workflow**: Save and activate the workflow. Your tickets from forwarded emails will now be processed correctly!"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "fd63feb9-6700-49e6-a522-45b3e2a161f2",
  "connections": {
    "Jira Trigger1": {
      "main": [
        [
          {
            "node": "Filter Forwarding Emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Customer1": {
      "main": [
        [
          {
            "node": "Update Reporter (New Customer)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Customer Exists": {
      "main": [
        [
          {
            "node": "Update Reporter (Existing Customer)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create Customer1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filter Forwarding Emails": {
      "main": [
        [
          {
            "node": "Set Description Variable",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Description Variable": {
      "main": [
        [
          {
            "node": "Parse Details From Description",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search for Existing Customer": {
      "main": [
        [
          {
            "node": "If Customer Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Details From Description": {
      "main": [
        [
          {
            "node": "Search for Existing Customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}