{
  "name": "Log transfer",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -2400,
        848
      ],
      "id": "7b80c181-0619-407a-849e-a8f14184bb9f",
      "name": "When clicking \u2018Execute workflow\u2019"
    },
    {
      "parameters": {
        "operation": "getAll",
        "returnAll": true,
        "options": {
          "jql": "issue = EQT01-141"
        }
      },
      "type": "n8n-nodes-base.jira",
      "typeVersion": 1,
      "position": [
        -2000,
        864
      ],
      "id": "191a9bc3-fbe1-4ebd-9bc5-21e4a0147ce9",
      "name": "Fetch Old Issues",
      "executeOnce": true,
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "getAll",
        "returnAll": true,
        "options": {
          "jql": "project = \"EQT15\""
        }
      },
      "type": "n8n-nodes-base.jira",
      "typeVersion": 1,
      "position": [
        -1776,
        864
      ],
      "id": "74b4673e-1d20-4ba6-81d6-47c77e6ad8e5",
      "name": "Fetch New Issues",
      "executeOnce": true,
      "credentials": {
        "jiraSoftwareCloudApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const oldIssues = $('Fetch Old Issues').all();\nconst newIssues = $('Fetch New Issues').all();\n\nreturn oldIssues.map(oldIssue => {\n    const oldKey = oldIssue.json.key;\n    \n    const matchedNew = newIssues.find(n => {\n        const summary = n.json.fields?.summary || \"\";\n        return summary.includes(`[${oldKey}]`);\n    });\n    \n    if (matchedNew) {\n        return {\n            json: {\n                oldKey: oldKey,\n                oldId: parseInt(oldIssue.json.id, 10), // <-- \u0414\u041e\u0411\u0410\u0412\u0418\u041b\u0418 \u042d\u0422\u0423 \u0421\u0422\u0420\u041e\u0427\u041a\u0423\n                newKey: matchedNew.json.key,\n                newId: parseInt(matchedNew.json.id, 10)\n            }\n        };\n    }\n    return null;\n}).filter(item => item !== null);"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1552,
        864
      ],
      "id": "a3c903f7-6ab8-4e1c-a8dc-ac7ca399a1ee",
      "name": "Map Old to New"
    },
    {
      "parameters": {
        "batchSize": 10,
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -1392,
        880
      ],
      "id": "09de62ff-2511-47b7-9a0a-5561a95942a8",
      "name": "Loop Tasks"
    },
    {
      "parameters": {
        "url": "=https://api.tempo.io/4/worklogs/issue/{{ $json.oldId }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "from",
              "value": "2026-05-01"
            },
            {
              "name": "to",
              "value": "2026-05-31"
            },
            {
              "name": "limit",
              "value": "1000"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        -1264,
        1200
      ],
      "id": "e1d3e899-f9d3-44d7-8327-0b204c4c9d17",
      "name": "Get Tempo Worklogs",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{ $json.results ? $json.results.length : 0 }}",
              "operation": "larger"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        -1072,
        864
      ],
      "id": "6fd9e75a-73b3-4c32-b62e-c188f97ea640",
      "name": "IF Worklogs Exist"
    },
    {
      "parameters": {
        "jsCode": "const allInputs = $input.all();\nconst mappings = $('Map Old to New').all();\n\nreturn allInputs.flatMap((item) => {\n  const results = item.json.results || [];\n\n  const currentOldId =\n    results[0]?.issue?.id ??\n    item.json.issue?.id ??\n    null;\n\n  const mapping = mappings.find(m => Number(m.json.oldId) === Number(currentOldId));\n  const newId = mapping?.json?.newId;\n\n  return results.map(wl => ({\n    json: {\n      issueId: newId,\n      oldIssueId: currentOldId,\n      timeSpentSeconds: wl.timeSpentSeconds,\n      startDate: wl.startDate,\n      startTime: wl.startTime || \"09:00:00\",\n      description: wl.description || \"Migrated worklog\",\n      authorAccountId: wl.author?.accountId,\n    }\n  }));\n});"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -784,
        864
      ],
      "id": "3221a33a-7a08-4bc3-be77-4dca872bb4b3",
      "name": "Prepare Tempo Data"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        -480,
        896
      ],
      "id": "ea0e0204-31c3-4f5b-b1c9-b01d0cb61f0f",
      "name": "Loop Worklogs"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.tempo.io/4/worklogs",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"issueId\": {{$json.issueId}},\n  \"timeSpentSeconds\": {{$json.timeSpentSeconds}},\n  \"startDate\": \"{{$json.startDate}}\",\n  \"startTime\": \"{{$json.startTime}}\",\n  \"description\": \"{{$json.description}}\",\n  \"authorAccountId\": \"{{$json.authorAccountId}}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        16,
        896
      ],
      "id": "bebcf6f0-a6b6-43e4-b66f-2765567c5359",
      "name": "Post Tempo Worklog",
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        -3040,
        1248
      ],
      "id": "78186964-c3a6-4367-aade-2a82c12a18ac",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -1248,
        992
      ],
      "id": "49dcaf0a-73cf-4f89-b96e-132f3dc9ddae",
      "name": "Wait"
    },
    {
      "parameters": {
        "amount": 10,
        "unit": "seconds"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        -224,
        896
      ],
      "id": "6adc012a-248b-4372-9297-15d33fccd89f",
      "name": "Wait 15s"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "26f78e68-1598-49a5-93b5-08d5fbafc9dd",
              "leftValue": "={{ $json.error ? \"yes\" : \"no\" }}",
              "rightValue": "yes",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        240,
        896
      ],
      "id": "8f1d1a6b-cc6f-4c7e-ad20-fa1857fb28f8",
      "name": "If"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": "REDACTED",
        "sheetName": {
          "__rl": true,
          "value": "REDACTED",
          "mode": "list",
          "cachedResultName": "REDACTED",
          "cachedResultUrl": "REDACTED"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Error Message": "={{ $json.error.message || $json.error || \"Unknown API Error\" }}",
            "New Issue ID": "={{ $('Loop Worklogs').item.json.issueId }}",
            "Old Issue ID": "={{ $('Loop Worklogs').item.json.oldIssueId }}",
            "Time Spent": "={{ $('Loop Worklogs').item.json.timeSpentSeconds }}",
            "Start Date": "={{ $('Loop Worklogs').item.json.startDate }}",
            "Author ID": "={{ $('Loop Worklogs').item.json.authorAccountId }}",
            "Description": "={{ $('Loop Worklogs').item.json.description }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Error Message",
              "displayName": "Error Message",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "New Issue ID",
              "displayName": "New Issue ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Old Issue ID",
              "displayName": "Old Issue ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Time Spent",
              "displayName": "Time Spent",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Start Date",
              "displayName": "Start Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Author ID",
              "displayName": "Author ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Description",
              "displayName": "Description",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        448,
        976
      ],
      "id": "938ec4cb-70dc-45c7-a683-eae45b08a0bf",
      "name": "Append row in sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Fetch Old Issues": {
      "main": [
        [
          {
            "node": "Fetch New Issues",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch New Issues": {
      "main": [
        [
          {
            "node": "Map Old to New",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Map Old to New": {
      "main": [
        [
          {
            "node": "Loop Tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Tasks": {
      "main": [
        [
          {
            "node": "IF Worklogs Exist",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Tempo Worklogs": {
      "main": [
        [
          {
            "node": "Loop Tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Worklogs Exist": {
      "main": [
        [
          {
            "node": "Prepare Tempo Data",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Prepare Tempo Data": {
      "main": [
        [
          {
            "node": "Loop Worklogs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Worklogs": {
      "main": [
        [],
        [
          {
            "node": "Wait 15s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post Tempo Worklog": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Fetch Old Issues",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Get Tempo Worklogs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 15s": {
      "main": [
        [
          {
            "node": "Post Tempo Worklog",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Append row in sheet",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Loop Worklogs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append row in sheet": {
      "main": [
        [
          {
            "node": "Loop Worklogs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": true,
    "timeSavedMode": "fixed",
    "errorWorkflow": "REDACTED",
    "callerPolicy": "workflowsFromSameOwner"
  }
}