{
  "id": "IIsrIl8ZXuHxxrrN",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Email-to-Jira Auto Ticket Creator (AI-powered) with n8n",
  "tags": [],
  "nodes": [
    {
      "id": "80da05bf-11e1-4e94-bdc2-c720d2e0149f",
      "name": "Fetch Full Email Content\t",
      "type": "n8n-nodes-base.gmail",
      "position": [
        220,
        0
      ],
      "parameters": {
        "simple": false,
        "options": {},
        "messageId": "={{ $json.id }}",
        "operation": "get"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "c674d95f-f1bb-4244-b894-357d44e95fbb",
      "name": "Analyze Email & Extract Tasks\t",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        440,
        0
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "=You are a Jira assistant.\n\nAnalyze the following email content and generate structured output in **pure JSON** format.\n\nInstructions:\n1. Identify if the email is about a \"feature\" or an \"issue\".\n2. Provide a short but clear summary (`main_ticket`) for the main ticket.\n3. Include a meaningful one-liner (`main_description`) describing the overall goal.\n4. Break down all actionable items into `sub_tasks`, each with:\n   - a short `summary`\n   - a short `description` that elaborates slightly more on the task.\n5. Respond ONLY in a valid JSON object. No extra explanation, no Markdown, no bullet points, no formatting \u2014 only raw JSON.\n\nExpected JSON format:\n{\n  \"category\": \"Issue\" | \"Feature\",\n  \"main_ticket\": \"Short summary of the main ticket\",\n  \"main_description\": \"One-liner describing the main ticket goal\",\n  \"sub_tasks\": [\n    {\n      \"summary\": \"Short sub-task summary\",\n      \"description\": \"Slightly more detailed description\"\n    },\n    ...\n  ]\n}\n\nuse think tool also if needed.\nInput:\n{{ $json.text }}\n"
        },
        "promptType": "define"
      },
      "typeVersion": 1.8
    },
    {
      "id": "51d2c717-4eda-4e1d-a155-eda1729b3c61",
      "name": "AI Tool - Think Support\t",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        588,
        220
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "5a611d35-2d2f-4508-99b1-c3ea3144b6bf",
      "name": "Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOllama",
      "position": [
        468,
        220
      ],
      "parameters": {
        "model": "=llama3.2",
        "options": {}
      },
      "credentials": {
        "ollamaApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "65448a27-838d-4860-8425-9ea8d9ad363a",
      "name": "Parse JSON Output from AI\t",
      "type": "n8n-nodes-base.code",
      "position": [
        1036,
        0
      ],
      "parameters": {
        "jsCode": "// Get the raw output from the previous AI Agent node\nconst rawOutput = $input.first().json.output;\n\n// Remove code block wrappers like ```json and ```\nconst cleaned = rawOutput\n  .replace(/^```json/, '')\n  .replace(/```$/, '')\n  .trim();\n\nlet parsed;\ntry {\n  parsed = JSON.parse(cleaned);\n} catch (err) {\n  throw new Error(\"Failed to parse AI output as JSON: \" + err.message);\n}\n\n// Now return the structured data so it can be used by later nodes\nreturn parsed;"
      },
      "typeVersion": 2
    },
    {
      "id": "e590efd2-0fdb-489f-ae41-e27d2b15afcf",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -20,
        -540
      ],
      "parameters": {
        "width": 540,
        "height": 440,
        "content": "\ud83d\udccc Email-to-Jira Auto Ticket Creator (AI-powered) \u2013 Overview\n\nThis AI-powered workflow reads emails, understands the request using an LLM, and creates structured Jira issues:\n\nFlow Steps:\n\n\ud83d\udce8 Polls for new emails every 5 minutes.\n\n\ud83d\udcec Fetches full email content.\n\n\ud83e\udde0 Analyzes content using AI to understand the issue or feature request.\n\n\ud83d\udcca Parses structured task data (main task + subtasks).\n\n\ud83e\uddfe Creates a main Jira task.\n\n\ud83e\uddfe Creates all related subtasks in Jira under the main task.\n\nPerfect for project teams who get work requests via email and want them converted into actionable Jira tickets automatically."
      },
      "typeVersion": 1
    },
    {
      "id": "4f22474a-0a1a-4902-b357-58aabd8c24c5",
      "name": "Check for New Emails\t",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "filters": {
          "sender": "user@example.com"
        },
        "pollTimes": {
          "item": [
            {
              "mode": "everyX",
              "unit": "minutes",
              "value": 5
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1e32f8e1-844e-45b0-b4ce-3e87b6e462ea",
      "name": "Jira - Create Main Issue",
      "type": "n8n-nodes-base.jira",
      "position": [
        1256,
        0
      ],
      "parameters": {
        "project": {
          "__rl": true,
          "mode": "id",
          "value": "10002"
        },
        "summary": "={{ $json.main_ticket }}",
        "issueType": {
          "__rl": true,
          "mode": "list",
          "value": "10008",
          "cachedResultName": "Task"
        },
        "additionalFields": {
          "assignee": {
            "__rl": true,
            "mode": "list",
            "value": "5fec3f15dd5eb501088e0226",
            "cachedResultName": "ajay"
          },
          "description": "={{ $json.main_description }}"
        }
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      },
      "executeOnce": false,
      "retryOnFail": false,
      "typeVersion": 1
    },
    {
      "id": "291a29fb-bce3-4553-af91-b9be4ab6eb6e",
      "name": "Create Subtasks\t",
      "type": "n8n-nodes-base.jira",
      "position": [
        1696,
        0
      ],
      "parameters": {
        "project": {
          "__rl": true,
          "mode": "id",
          "value": "10002"
        },
        "summary": "={{ $json.sub_task.summary }}",
        "issueType": {
          "__rl": true,
          "mode": "list",
          "value": "10010",
          "cachedResultName": "Subtask"
        },
        "additionalFields": {
          "assignee": {
            "__rl": true,
            "mode": "list",
            "value": "5fec3f15dd5eb501088e0226",
            "cachedResultName": "ajay"
          },
          "description": "={{ $json.sub_task.description }}",
          "parentIssueKey": "={{ $('Jira - Create Main Issue').item.json.key }}"
        }
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d2912bbc-177d-4683-b8ec-c54167148931",
      "name": "Split Subtasks JSON to Items\t",
      "type": "n8n-nodes-base.code",
      "position": [
        1476,
        0
      ],
      "parameters": {
        "jsCode": "const subtasks = $('Parse JSON Output from AI\t').first().json.sub_tasks;\n\nreturn subtasks.map(task => {\n  return {\n    json: {\n      sub_task: task\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "1f1f7172-bc9d-4e48-ac2d-d7f59f396b4a",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "position": [
        800,
        0
      ],
      "parameters": {},
      "typeVersion": 1.1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "5b67825d-b2f8-46f9-ba92-9ea9727c8d22",
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Parse JSON Output from AI\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze Email & Extract Tasks\t",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Check for New Emails\t": {
      "main": [
        [
          {
            "node": "Fetch Full Email Content\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Tool - Think Support\t": {
      "ai_tool": [
        [
          {
            "node": "Analyze Email & Extract Tasks\t",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Jira - Create Main Issue": {
      "main": [
        [
          {
            "node": "Split Subtasks JSON to Items\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Full Email Content\t": {
      "main": [
        [
          {
            "node": "Analyze Email & Extract Tasks\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse JSON Output from AI\t": {
      "main": [
        [
          {
            "node": "Jira - Create Main Issue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Subtasks JSON to Items\t": {
      "main": [
        [
          {
            "node": "Create Subtasks\t",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Analyze Email & Extract Tasks\t": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}