Build Your First Workflow with n8n
n8nWorkflow
Step-by-step tutorial for building your first AI automation workflow with n8n.
Build Your First Workflow with n8n
Introduction
n8n is a powerful workflow automation platform that makes it easy to connect apps and automate tasks. This tutorial will guide you through building your first AI-powered workflow.
Prerequisites
- An n8n account (self-hosted or cloud)
- Basic understanding of APIs
- An OpenAI API key (for AI nodes)
Step 1: Install n8n
Cloud Version
- Go to n8n.cloud
- Create a free account
- Start your workflow editor
Self-Hosted
npm install n8n -g
n8n start
Step 2: Create Your First Workflow
- Click Create Workflow in the dashboard
- Give it a name (e.g., "AI Email Summarizer")
- Start building your workflow
Step 3: Add Nodes
Trigger Node
Add a trigger to start your workflow:
- Webhook - Triggered by HTTP requests
- Schedule - Runs on a timer
- Email - Triggered by incoming emails
AI Node
Add an AI node for language processing:
- Search for OpenAI Chat Model
- Configure with your API key
- Set the model (e.g.,
gpt-4)
Action Node
Add an action to take after AI processing:
- Send Email - Send results via email
- Post to Slack - Share results in a channel
- Create Google Doc - Save results as a document
Step 4: Connect the Nodes
- Click and drag from one node to another
- The arrow shows the flow direction
- Test each connection
Example: AI Email Summarizer
[Email Trigger] → [OpenAI Summarize] → [Send Slack Message]
Configuration
OpenAI Node:
{
"model": "gpt-4",
"prompt": "Summarize this email in 3 bullet points:\n{{ $json.body }}"
}
Slack Node:
{
"channel": "#ai-summaries",
"text": "{{ $json.summary }}"
}
Best Practices
- Name your nodes clearly - Makes debugging easier
- Add error handling - Use error triggers for failures
- Test incrementally - Test each node separately
- Use credentials securely - Store API keys in n8n credentials
- Document your workflows - Add notes for complex logic
Advanced Features
Error Handling
Add an error trigger to catch and handle failures:
// Error handler
{
"error": "{{ $json.error.message }}",
"workflow": "{{ $workflow.name }}"
}
Data Transformation
Use the Code node for custom data transformation:
// Transform incoming data
return items.map(item => ({
json: {
...item.json,
processed: true,
timestamp: new Date().toISOString()
}
}));
Webhooks
Create a webhook endpoint:
- Add a Webhook node
- Choose POST method
- Copy the webhook URL
- Use it to trigger your workflow from external apps
