Automating n8n Workflow Creation via Agents (Local Setup)
I’m currently exploring how to automate the creation of n8n workflows using Agents in my locally hosted setup. While n8n is powerful, it doesn’t yet offer a clean way to programmatically create workflows without using the browser.
The Current Limitation
The only officially supported method to create a workflow is via the n8n browser UI. This is a blocker for full automation. Since I’m hosting it locally, I was hoping for an API or CLI-based way to inject workflows, but:
- There’s no documented public API for workflow creation.
- All automation right now would require browser-based interaction, like simulating clicks and inputs via tools such as Puppeteer or Playwright.
Alternatives I’m Considering
1. Generate Workflow JSON via LLM
I can ask an LLM to generate the workflow JSON based on the logic I need. This JSON is structured and can be exported/imported manually in the n8n UI.
But even here:
- I’m not sure if browser-use agents can simulate the drag-and-drop import or trigger the “import from JSON” via the UI.
- I might need to simulate the full import process using browser automation, which can be fragile.
2. Explore Internal APIs or DB Injection (Advanced)
Since I host n8n locally, I’m considering:
- Checking for any undocumented internal APIs (via browser network/dev tools).
- Looking into the **underlying database ** to directly insert workflow JSON (risky, but possible).
- Reviewing n8n’s file structure or boot scripts to see if workflows can be injected during startup.
3. Trigger Import via Browser Automation
I may write an agent that:
- Logs into the local instance.
- Navigates to the workflow page.
- Triggers the import dialog.
- Pastes the generated JSON.
- Saves the workflow.
This is hacky but could be wrapped into a repeatable automation agent.
Ideal Solution (Not Yet Available)
The ideal long-term solution would be:
- A REST API endpoint for workflow creation.
- A CLI tool or SDK that supports importing/exporting workflows programmatically.