{
  "updatedAt": "2025-12-23T01:51:31.152Z",
  "createdAt": "2025-12-11T00:55:14.379Z",
  "id": "Mu7fMoOkpLXeZKCU",
  "name": "Backup Workflows To Github (Proper Names)",
  "active": true,
  "isArchived": false,
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1235fed-ae2f-4520-9158-2cf406bb2586",
              "leftValue": "={{ $('List Workflow Files on Github').all().map(item => item.json.name) }}",
              "rightValue": "={{ $json.name }}",
              "operator": {
                "type": "array",
                "operation": "contains",
                "rightType": "any"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -864,
        208
      ],
      "id": "8d0edd38-7250-47ea-9fa2-636a8ec411fd",
      "name": "If File Exists"
    },
    {
      "parameters": {
        "operation": "fromJson",
        "options": {}
      },
      "type": "n8n-nodes-base.extractFromFile",
      "typeVersion": 1,
      "position": [
        -416,
        112
      ],
      "id": "9cb3dd8f-b506-402b-a9ad-2882fec0a56c",
      "name": "Extract from File"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -1760,
        208
      ],
      "id": "efc5c5d3-170c-436d-a3af-70a6f546e80b",
      "name": "Run Daily"
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "list",
        "owner": {
          "__rl": true,
          "value": "adamhaley",
          "mode": "name"
        },
        "repository": {
          "__rl": true,
          "value": "megyk-automations",
          "mode": "list",
          "cachedResultName": "megyk-automations",
          "cachedResultUrl": "https://github.com/adamhaley/megyk-automations"
        },
        "filePath": "workflows"
      },
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [
        -1536,
        208
      ],
      "id": "7d905908-8178-4b7e-8b01-7f658f217b73",
      "name": "List Workflow Files on Github",
      "executeOnce": true,
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet name =  $json.name.replace(/ /g,'_');\nname = name.replace('/','') + '.json';\nreturn { name: name }"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1088,
        208
      ],
      "id": "d1361a36-8b99-4a17-bb5e-a1ec0a5da4a6",
      "name": "Proper filename from Workflow",
      "executeOnce": false
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "get",
        "owner": {
          "__rl": true,
          "value": "adamhaley",
          "mode": "name"
        },
        "repository": {
          "__rl": true,
          "value": "megyk-automations",
          "mode": "list",
          "cachedResultName": "megyk-automations",
          "cachedResultUrl": "https://github.com/adamhaley/megyk-automations"
        },
        "filePath": "=workflows/{{ $json.name }}",
        "additionalParameters": {}
      },
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [
        -640,
        112
      ],
      "id": "56a6ffee-3232-4313-b134-714b68f03f20",
      "name": "Get The File",
      "executeOnce": false,
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "filters": {
          "activeWorkflows": true,
          "tags": ""
        },
        "requestOptions": {}
      },
      "type": "n8n-nodes-base.n8n",
      "typeVersion": 1,
      "position": [
        -1312,
        208
      ],
      "id": "7c7d2d3d-879a-4819-abca-77aa5cd2db5e",
      "name": "n8n Get Active Workflows",
      "executeOnce": true,
      "credentials": {
        "n8nApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "file",
        "owner": {
          "__rl": true,
          "value": "adamhaley",
          "mode": "name"
        },
        "repository": {
          "__rl": true,
          "value": "megyk-automations",
          "mode": "list",
          "cachedResultName": "megyk-automations",
          "cachedResultUrl": "https://github.com/adamhaley/megyk-automations"
        },
        "filePath": "=workflows/{{$json.name  }}",
        "fileContent": "={{ JSON.stringify( $('n8n Get Active Workflows').item.json, null, 2 ) }}",
        "commitMessage": "=creating backup file for workflow \"{{ $('n8n Get Active Workflows').item.json.name }}\"\"",
        "additionalParameters": {
          "branch": {
            "branch": "main"
          }
        }
      },
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [
        -640,
        304
      ],
      "id": "8186f6a2-e2aa-49fd-96d5-3419986f2697",
      "name": "Create File on Github",
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "edit",
        "owner": {
          "__rl": true,
          "value": "adamhaley",
          "mode": "name"
        },
        "repository": {
          "__rl": true,
          "value": "megyk-automations",
          "mode": "list",
          "cachedResultName": "megyk-automations",
          "cachedResultUrl": "https://github.com/adamhaley/megyk-automations"
        },
        "filePath": "=workflows/{{ $('Get The File').item.json.name }}",
        "fileContent": "={{ JSON.stringify( $('n8n Get Active Workflows').item.json, null, 2 ) }}",
        "commitMessage": "=Updating n8n workflow \"{{ $('n8n Get Active Workflows').item.json.name }}\""
      },
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [
        32,
        16
      ],
      "id": "e763d77c-5297-42cc-a652-f11059c5c405",
      "name": "Update File on GIthub",
      "credentials": {
        "githubApi": {
          "name": "<your credential>"
        }
      },
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "c9576a13-befb-4a51-85e2-7ee04cb3664f",
              "leftValue": "={{ JSON.stringify( $('Extract from File').item.json.data, null, 2 ) }}",
              "rightValue": "={{ JSON.stringify( $('n8n Get Active Workflows').item.json, null, 2 ) }}",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -192,
        112
      ],
      "id": "0ab5212b-fe76-4b91-9ab8-2c78f0322673",
      "name": "if n8n Workflow has Updates"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        32,
        208
      ],
      "id": "de2d2481-13f1-47a7-a93a-24ba14949e91",
      "name": "No Operation, do nothing"
    }
  ],
  "connections": {
    "If File Exists": {
      "main": [
        [
          {
            "node": "Get The File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create File on Github",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "if n8n Workflow has Updates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Daily": {
      "main": [
        [
          {
            "node": "List Workflow Files on Github",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Workflow Files on Github": {
      "main": [
        [
          {
            "node": "n8n Get Active Workflows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Proper filename from Workflow": {
      "main": [
        [
          {
            "node": "If File Exists",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get The File": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "n8n Get Active Workflows": {
      "main": [
        [
          {
            "node": "Proper filename from Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update File on GIthub": {
      "main": [
        [],
        []
      ]
    },
    "Create File on Github": {
      "main": [
        []
      ]
    },
    "if n8n Workflow has Updates": {
      "main": [
        [
          {
            "node": "Update File on GIthub",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "timeSavedMode": "fixed",
    "callerPolicy": "workflowsFromSameOwner",
    "availableInMCP": false,
    "errorWorkflow": "WbISMAIlclQfzorG"
  },
  "staticData": {
    "node:Run Daily": {
      "recurrenceRules": []
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "versionId": "f3c47bee-22de-4348-88eb-dc30f2553488",
  "activeVersionId": "f3c47bee-22de-4348-88eb-dc30f2553488",
  "triggerCount": 1,
  "shared": [
    {
      "updatedAt": "2025-12-11T00:55:14.388Z",
      "createdAt": "2025-12-11T00:55:14.388Z",
      "role": "workflow:owner",
      "workflowId": "Mu7fMoOkpLXeZKCU",
      "projectId": "B7QJE85HA2Vij1it"
    }
  ],
  "activeVersion": {
    "updatedAt": "2025-12-23T01:51:33.000Z",
    "createdAt": "2025-12-21T17:19:52.286Z",
    "versionId": "f3c47bee-22de-4348-88eb-dc30f2553488",
    "workflowId": "Mu7fMoOkpLXeZKCU",
    "nodes": [
      {
        "parameters": {
          "conditions": {
            "options": {
              "caseSensitive": true,
              "leftValue": "",
              "typeValidation": "strict",
              "version": 2
            },
            "conditions": [
              {
                "id": "c1235fed-ae2f-4520-9158-2cf406bb2586",
                "leftValue": "={{ $('List Workflow Files on Github').all().map(item => item.json.name) }}",
                "rightValue": "={{ $json.name }}",
                "operator": {
                  "type": "array",
                  "operation": "contains",
                  "rightType": "any"
                }
              }
            ],
            "combinator": "and"
          },
          "options": {}
        },
        "type": "n8n-nodes-base.if",
        "typeVersion": 2.2,
        "position": [
          -864,
          208
        ],
        "id": "8d0edd38-7250-47ea-9fa2-636a8ec411fd",
        "name": "If File Exists"
      },
      {
        "parameters": {
          "operation": "fromJson",
          "options": {}
        },
        "type": "n8n-nodes-base.extractFromFile",
        "typeVersion": 1,
        "position": [
          -416,
          112
        ],
        "id": "9cb3dd8f-b506-402b-a9ad-2882fec0a56c",
        "name": "Extract from File"
      },
      {
        "parameters": {
          "rule": {
            "interval": [
              {}
            ]
          }
        },
        "type": "n8n-nodes-base.scheduleTrigger",
        "typeVersion": 1.2,
        "position": [
          -1760,
          208
        ],
        "id": "efc5c5d3-170c-436d-a3af-70a6f546e80b",
        "name": "Run Daily"
      },
      {
        "parameters": {
          "resource": "file",
          "operation": "list",
          "owner": {
            "__rl": true,
            "value": "adamhaley",
            "mode": "name"
          },
          "repository": {
            "__rl": true,
            "value": "megyk-automations",
            "mode": "list",
            "cachedResultName": "megyk-automations",
            "cachedResultUrl": "https://github.com/adamhaley/megyk-automations"
          },
          "filePath": "workflows"
        },
        "type": "n8n-nodes-base.github",
        "typeVersion": 1,
        "position": [
          -1536,
          208
        ],
        "id": "7d905908-8178-4b7e-8b01-7f658f217b73",
        "name": "List Workflow Files on Github",
        "executeOnce": true,
        "webhookId": "ef7828ec-cf4d-42a9-b12f-5c088cf829ec",
        "credentials": {
          "githubApi": {
            "id": "2omAzGRnpCrb3ZGb",
            "name": "GitHub account"
          }
        }
      },
      {
        "parameters": {
          "mode": "runOnceForEachItem",
          "jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet name =  $json.name.replace(/ /g,'_');\nname = name.replace('/','') + '.json';\nreturn { name: name }"
        },
        "type": "n8n-nodes-base.code",
        "typeVersion": 2,
        "position": [
          -1088,
          208
        ],
        "id": "d1361a36-8b99-4a17-bb5e-a1ec0a5da4a6",
        "name": "Proper filename from Workflow",
        "executeOnce": false
      },
      {
        "parameters": {
          "resource": "file",
          "operation": "get",
          "owner": {
            "__rl": true,
            "value": "adamhaley",
            "mode": "name"
          },
          "repository": {
            "__rl": true,
            "value": "megyk-automations",
            "mode": "list",
            "cachedResultName": "megyk-automations",
            "cachedResultUrl": "https://github.com/adamhaley/megyk-automations"
          },
          "filePath": "=workflows/{{ $json.name }}",
          "additionalParameters": {}
        },
        "type": "n8n-nodes-base.github",
        "typeVersion": 1,
        "position": [
          -640,
          112
        ],
        "id": "56a6ffee-3232-4313-b134-714b68f03f20",
        "name": "Get The File",
        "executeOnce": false,
        "webhookId": "c6bcc826-6787-45c1-a756-6aedb5fd81b7",
        "credentials": {
          "githubApi": {
            "id": "2omAzGRnpCrb3ZGb",
            "name": "GitHub account"
          }
        }
      },
      {
        "parameters": {
          "filters": {
            "activeWorkflows": true,
            "tags": ""
          },
          "requestOptions": {}
        },
        "type": "n8n-nodes-base.n8n",
        "typeVersion": 1,
        "position": [
          -1312,
          208
        ],
        "id": "7c7d2d3d-879a-4819-abca-77aa5cd2db5e",
        "name": "n8n Get Active Workflows",
        "executeOnce": true,
        "credentials": {
          "n8nApi": {
            "id": "lo23nGVR8nVRtIwQ",
            "name": "n8n account"
          }
        }
      },
      {
        "parameters": {
          "resource": "file",
          "owner": {
            "__rl": true,
            "value": "adamhaley",
            "mode": "name"
          },
          "repository": {
            "__rl": true,
            "value": "megyk-automations",
            "mode": "list",
            "cachedResultName": "megyk-automations",
            "cachedResultUrl": "https://github.com/adamhaley/megyk-automations"
          },
          "filePath": "=workflows/{{$json.name  }}",
          "fileContent": "={{ JSON.stringify( $('n8n Get Active Workflows').item.json, null, 2 ) }}",
          "commitMessage": "=creating backup file for workflow \"{{ $('n8n Get Active Workflows').item.json.name }}\"\"",
          "additionalParameters": {
            "branch": {
              "branch": "main"
            }
          }
        },
        "type": "n8n-nodes-base.github",
        "typeVersion": 1,
        "position": [
          -640,
          304
        ],
        "id": "8186f6a2-e2aa-49fd-96d5-3419986f2697",
        "name": "Create File on Github",
        "webhookId": "23889cba-d3e7-4dd0-ab91-4b262d0112f1",
        "credentials": {
          "githubApi": {
            "id": "2omAzGRnpCrb3ZGb",
            "name": "GitHub account"
          }
        },
        "onError": "continueRegularOutput"
      },
      {
        "parameters": {
          "resource": "file",
          "operation": "edit",
          "owner": {
            "__rl": true,
            "value": "adamhaley",
            "mode": "name"
          },
          "repository": {
            "__rl": true,
            "value": "megyk-automations",
            "mode": "list",
            "cachedResultName": "megyk-automations",
            "cachedResultUrl": "https://github.com/adamhaley/megyk-automations"
          },
          "filePath": "=workflows/{{ $('Get The File').item.json.name }}",
          "fileContent": "={{ JSON.stringify( $('n8n Get Active Workflows').item.json, null, 2 ) }}",
          "commitMessage": "=Updating n8n workflow \"{{ $('n8n Get Active Workflows').item.json.name }}\""
        },
        "type": "n8n-nodes-base.github",
        "typeVersion": 1,
        "position": [
          32,
          16
        ],
        "id": "e763d77c-5297-42cc-a652-f11059c5c405",
        "name": "Update File on GIthub",
        "webhookId": "f6489b4e-6185-449d-b876-e17fd2afbbd1",
        "credentials": {
          "githubApi": {
            "id": "2omAzGRnpCrb3ZGb",
            "name": "GitHub account"
          }
        },
        "onError": "continueErrorOutput"
      },
      {
        "parameters": {
          "conditions": {
            "options": {
              "caseSensitive": true,
              "leftValue": "",
              "typeValidation": "strict",
              "version": 2
            },
            "conditions": [
              {
                "id": "c9576a13-befb-4a51-85e2-7ee04cb3664f",
                "leftValue": "={{ JSON.stringify( $('Extract from File').item.json.data, null, 2 ) }}",
                "rightValue": "={{ JSON.stringify( $('n8n Get Active Workflows').item.json, null, 2 ) }}",
                "operator": {
                  "type": "string",
                  "operation": "notEquals"
                }
              }
            ],
            "combinator": "and"
          },
          "options": {}
        },
        "type": "n8n-nodes-base.if",
        "typeVersion": 2.2,
        "position": [
          -192,
          112
        ],
        "id": "0ab5212b-fe76-4b91-9ab8-2c78f0322673",
        "name": "if n8n Workflow has Updates"
      },
      {
        "parameters": {},
        "type": "n8n-nodes-base.noOp",
        "typeVersion": 1,
        "position": [
          32,
          208
        ],
        "id": "de2d2481-13f1-47a7-a93a-24ba14949e91",
        "name": "No Operation, do nothing"
      }
    ],
    "connections": {
      "If File Exists": {
        "main": [
          [
            {
              "node": "Get The File",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "Create File on Github",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Extract from File": {
        "main": [
          [
            {
              "node": "if n8n Workflow has Updates",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Run Daily": {
        "main": [
          [
            {
              "node": "List Workflow Files on Github",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "List Workflow Files on Github": {
        "main": [
          [
            {
              "node": "n8n Get Active Workflows",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Proper filename from Workflow": {
        "main": [
          [
            {
              "node": "If File Exists",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Get The File": {
        "main": [
          [
            {
              "node": "Extract from File",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "n8n Get Active Workflows": {
        "main": [
          [
            {
              "node": "Proper filename from Workflow",
              "type": "main",
              "index": 0
            }
          ]
        ]
      },
      "Update File on GIthub": {
        "main": [
          [],
          []
        ]
      },
      "Create File on Github": {
        "main": [
          []
        ]
      },
      "if n8n Workflow has Updates": {
        "main": [
          [
            {
              "node": "Update File on GIthub",
              "type": "main",
              "index": 0
            }
          ],
          [
            {
              "node": "No Operation, do nothing",
              "type": "main",
              "index": 0
            }
          ]
        ]
      }
    },
    "nodeGroups": [],
    "authors": "Gordan Kljajic",
    "name": "Version f3c47bee",
    "description": "",
    "autosaved": false
  },
  "tags": []
}