Quick overview
This workflow is called by another n8n workflow to export a selected n8n workflow as a JSON file and sync it to a GitHub repository, creating the file if it doesn’t exist and updating it only when the workflow definition changes.
How it works
- Receives a workflow ID as input when executed by another n8n workflow.
- Fetches the workflow definition from the n8n API using the provided workflow ID.
- Reduces the workflow data to essential fields (such as name, nodes, connections, and settings) and converts it into a formatted JSON file.
- Tries to retrieve a same-named JSON file from a GitHub repository.
- If the file does not exist, creates it in GitHub with an initial commit message.
- If the file exists and the content differs from the current workflow JSON, updates the GitHub file with a new commit.
Setup
- Create an n8n API credential with access to read workflows and select it in the n8n node used to fetch workflows.
- Add a GitHub credential with permission to read and write files in the target repository.
- Update the GitHub owner and repository values (and optionally the commit message patterns) to match where you want to store the exported workflow JSON files.
- Ensure the calling workflow passes a valid “Workflow Id” input when executing this workflow.