n8n Workflow

Backup Workflows To Github

This n8n workflow automates tasks using GitHub. Backup Workflows To Github - ready to import and run in your n8n instance.

n8n workflow.json

About This Script

This n8n workflow automates tasks using GitHub. Backup Workflows To Github - ready to import and run in your n8n instance.
Features:
  • Custom JavaScript function processing
  • Makes HTTP requests to external APIs
  • Scheduled automation with cron triggers
  • Integrates with GitHub
Source Code
{
    "nodes": [
        {
            "name": "GitHub Edit",
            "type": "n8n-nodes-base.github",
            "position": [
                1190,
                610
            ],
            "parameters": {
                "owner": "YOUR_USERNAME",
                "filePath": "={{$json[\"data\"][\"name\"]}}.json",
                "resource": "file",
                "operation": "edit",
                "repository": "REPO_NAME",
                "fileContent": "={{JSON.stringify($json[\"data\"])}}",
                "commitMessage": "=[N8N Backup] {{$json.data[\"name\"]}} ({{new Date(Date.now()).toLocaleDateString()}})"
            },
            "credentials": {
                "githubApi": "GitHub@harshil1712"
            },
            "typeVersion": 1,
            "id": "993e79ea-e48a-43de-b509-2e897c3aa92c"
        },
        {
            "name": "Get Files",
            "type": "n8n-nodes-base.github",
            "position": [
                200,
                500
            ],
            "parameters": {
                "owner": "YOUR_USERNAME",
                "filePath": "/",
                "resource": "file",
                "operation": "get",
                "repository": "REPO",
                "asBinaryProperty": false
            },
            "credentials": {
                "githubApi": "GitHub@harshil1712"
            },
            "executeOnce": true,
            "typeVersion": 1,
            "alwaysOutputData": false,
            "id": "8aba226b-1b5b-4338-a755-f963c5b0d80f"
        },
        {
            "name": "Transform",
            "type": "n8n-nodes-base.function",
            "position": [
                400,
                500
            ],
            "parameters": {
                "functionCode": "return items[0].json.map(item => {\n  return {\n    json: item\n  }\n});\n"
            },
            "typeVersion": 1,
            "id": "58447716-7a7e-41db-953d-6080a538d6ed"
        },
        {
            "name": "Create file",
            "type": "n8n-nodes-base.github",
            "position": [
                1240,
                280
            ],
            "parameters": {
                "owner": "YOUR_USERNAME",
                "filePath": "={{$json[\"data\"][\"name\"]}}.json",
                "resource": "file",
                "repository": "REPO",
                "fileContent": "={{JSON.stringify($node['Merge'].json[\"data\"])}}",
                "commitMessage": "=[N8N Backup] {{$json.data[\"name\"]}}.json ({{new Date(Date.now()).toLocaleDateString()}})"
            },
            "credentials": {
                "githubApi": "GitHub@harshil1712"
            },
            "typeVersion": 1,
            "id": "a0868a07-fdaa-416e-8cf3-a245d51199c8"
        },
        {
            "name": "Merge",
            "type": "n8n-nodes-base.merge",
            "position": [
                930,
                280
            ],
            "parameters": {
                "mode": "removeKeyMatches",
                "propertyName1": "data.name",
                "propertyName2": "data.name"
            },
            "typeVersion": 1,
            "id": "1823ce57-44b9-47c5-8fc7-ab63c642c905"
        },
        {
            "name": "Get workflows",
            "type": "n8n-nodes-base.httpRequest",
            "position": [
                200,
                300
            ],
            "parameters": {
                "url": "http://localhost:5678/rest/workflows",
                "options": [],
                "authentication": "basicAuth"
            },
            "credentials": {
                "httpBasicAuth": "n8n instance auth"
            },
            "typeVersion": 1,
            "id": "8fa90ef4-40f7-4156-9b51-fd1fb8ba3faa"
        },
        {
            "name": "Get workflow data",
            "type": "n8n-nodes-base.httpRequest",
            "position": [
                600,
                300
            ],
            "parameters": {
                "url": "=http://localhost:5678/rest/workflows/{{$json[\"id\"]}}",
                "options": [],
                "authentication": "basicAuth"
            },
            "credentials": {
                "httpBasicAuth": "n8n instance auth"
            },
            "typeVersion": 1,
            "id": "f37e3e81-c641-4995-82e0-8fac6596956e"
        },
        {
            "name": "Download Raw Content",
            "type": "n8n-nodes-base.httpRequest",
            "position": [
                600,
                500
            ],
            "parameters": {
                "url": "={{$json[\"download_url\"]}}",
                "options": [],
                "authentication": "headerAuth",
                "responseFormat": "string"
            },
            "credentials": {
                "httpHeaderAuth": "GitHub Token"
            },
            "typeVersion": 1,
            "id": "7afb431c-5319-4a5b-9abb-475ae086d4b2"
        },
        {
            "name": "transform",
            "type": "n8n-nodes-base.function",
            "position": [
                390,
                300
            ],
            "parameters": {
                "functionCode": "const newItems = [];\nfor (item of items[0].json.data) {\n  newItems.push({json: item});\n}\nreturn newItems;"
            },
            "typeVersion": 1,
            "id": "e5d3dac2-9d2d-4f0c-be87-a3b84b6d391f"
        },
        {
            "name": "Daily at 23:59",
            "type": "n8n-nodes-base.cron",
            "position": [
                -20,
                300
            ],
            "parameters": {
                "triggerTimes": {
                    "item": [
                        {
                            "hour": 23,
                            "minute": 59
                        }
                    ]
                }
            },
            "typeVersion": 1,
            "id": "9c0bda0e-bc31-4bce-b947-04707145b812"
        },
        {
            "name": "Merge1",
            "type": "n8n-nodes-base.merge",
            "position": [
                970,
                610
            ],
            "parameters": {
                "mode": "removeKeyMatches",
                "propertyName1": "data.updatedAt",
                "propertyName2": "data.updatedAt"
            },
            "typeVersion": 1,
            "id": "c22c2b56-fa15-488e-825b-d1a8f3ea192f"
        }
    ],
    "connections": {
        "Merge": {
            "main": [
                [
                    {
                        "node": "Create file",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Merge1": {
            "main": [
                [
                    {
                        "node": "GitHub Edit",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Get Files": {
            "main": [
                [
                    {
                        "node": "Transform",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Transform": {
            "main": [
                [
                    {
                        "node": "Download Raw Content",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "transform": {
            "main": [
                [
                    {
                        "node": "Get workflow data",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Get workflows": {
            "main": [
                [
                    {
                        "node": "transform",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Daily at 23:59": {
            "main": [
                [
                    {
                        "node": "Get workflows",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Get workflow data": {
            "main": [
                [
                    {
                        "node": "Merge",
                        "type": "main",
                        "index": 0
                    },
                    {
                        "node": "Merge1",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Download Raw Content": {
            "main": [
                [
                    {
                        "node": "Merge",
                        "type": "main",
                        "index": 1
                    },
                    {
                        "node": "Merge1",
                        "type": "main",
                        "index": 1
                    }
                ]
            ]
        }
    },
    "n8n_version": "1.5.0"
}
Requirements
n8n instance, Github API credentials
Tags
#n8n #automation #workflow
Quick Actions
More in n8n Workflows