N8nTutorial

Tutorial 1: Build Your First n8n Workflow

Build a complete weather notification workflow from scratch. This hands-on tutorial will teach you n8n fundamentals by creating something useful and real.

15 min read

Tutorial 1: Build Your First n8n Workflow

Build a complete weather notification workflow from scratch. This hands-on tutorial will teach you n8n fundamentals by creating something useful and real.

Duration: 45 minutes Difficulty: Beginner Prerequisites: n8n installed (Docker or npm)


Table of Contents

  1. What You'll Build
  2. Prerequisites
  3. Part 1: Setup & Installation
  4. Part 2: Create Your First Workflow
  5. Part 3: Add Schedule Trigger
  6. Part 4: Fetch Weather Data
  7. Part 5: Transform the Data
  8. Part 6: Send Notification
  9. Part 7: Test & Debug
  10. Part 8: Activate Your Workflow
  11. Troubleshooting
  12. Next Steps

What You'll Build

You'll create an automated weather notification system that:

  • ✅ Runs automatically every morning at 8 AM
  • ✅ Fetches current weather from OpenWeatherMap API
  • ✅ Formats data into a readable message
  • ✅ Sends notification to Slack (or email)
  • ✅ Handles errors gracefully

Final Output Example:

What You'll Learn:

  • n8n interface navigation
  • Creating and connecting nodes
  • Working with HTTP requests
  • Data transformation with Code nodes
  • Scheduling workflows
  • Credential management
  • Testing and debugging
  • Activating workflows

Prerequisites

Required

1. n8n Running Locally

Choose one method:

Option A: Docker (Recommended)

Option B: npm

Verify by visiting http://localhost:5678 in your browser.

2. Free OpenWeatherMap API Key

  1. Sign up at openweathermap.org
  2. Get free API key (Current Weather Data API)
  3. Note: API may take 10-20 minutes to activate

3. Slack Workspace (Optional)

  • For Slack notifications: Admin access to create webhooks
  • Alternative: Use Email node instead (Gmail, Outlook, etc.)

Optional but Helpful

  • Basic understanding of JSON
  • Familiarity with APIs (we'll explain everything)

Part 1: Setup & Installation

Step 1.1: Verify n8n is Running

  1. Open browser to http://localhost:5678
  2. You should see the n8n interface
  3. If first time, create owner account:

Step 1.2: Familiarize with Interface

Take 2 minutes to explore:

Left Panel: Search for nodes Center Canvas: Where you build workflows Right Panel: Node settings (when node selected) Top Bar: Workflow controls (Execute, Save, Activate)

Step 1.3: Get Your API Keys Ready

OpenWeatherMap:

  • Login to OpenWeatherMap account
  • Go to API Keys section
  • Copy your API key
  • Keep handy for Step 4

Slack (Optional):

  • Go to api.slack.com/apps
  • Create new app
  • Add "Incoming Webhooks"
  • Copy webhook URL

Part 2: Create Your First Workflow

Step 2.1: Create New Workflow

  1. Click "New Workflow" (+ icon top left)
  2. You'll see an empty canvas
  3. Click workflow name (top left) and rename to: Weather Notification

Step 2.2: Add a Sticky Note (Documentation)

Let's document our workflow:

  1. Right-click on canvas
  2. Select "Add Sticky Note"
  3. Add this text:

Good practice: Always document workflows!


Part 3: Add Schedule Trigger

Workflows need a trigger to start. We'll use a schedule trigger.

Step 3.1: Add Schedule Trigger Node

  1. Click anywhere on canvas
  2. Search for "Schedule Trigger"
  3. Click to add it

You'll see the node appear with settings panel on right.

Step 3.2: Configure the Schedule

In the right settings panel:

  1. Trigger Interval: Select "Days"
  2. Days Between Triggers: Enter 1 (daily)
  3. Trigger Time: Set to 08:00
  4. Trigger at Day Start: Keep default

Your workflow will now run every day at 8 AM.

Step 3.3: Test the Trigger

  1. Click "Execute Node" button (on the trigger)
  2. You should see green checkmark ✓
  3. Bottom panel shows execution time
  4. This confirms trigger works!

💡 Tip: "Execute Node" tests individual nodes manually.


Part 4: Fetch Weather Data

Now let's get weather data from OpenWeatherMap API.

Step 4.1: Add HTTP Request Node

  1. Click the + button on the right side of Schedule Trigger
  2. Search for "HTTP Request"
  3. Select the node

Step 4.2: Configure API Request

In the HTTP Request settings:

Authentication: None (we'll use API key in URL)

Method: GET

URL:

Query Parameters:

Add these parameters (click "Add Parameter"):

Name Value
q San Francisco
appid YOUR_API_KEY_HERE
units imperial

Replace YOUR_API_KEY_HERE with your actual OpenWeatherMap API key.

What these parameters do:

  • q: City name (you can change to your city)
  • appid: Your API authentication key
  • units: imperial (Fahrenheit) or metric (Celsius)

Step 4.3: Test the API Call

  1. Click "Execute Node"
  2. Wait a few seconds
  3. Check bottom panel - you should see JSON response
  4. Expand the data to see weather information

Expected Response Structure:

Step 4.4: Understanding the Data

Look at the JSON response in the output panel. Key fields:

  • name: City name
  • main.temp: Temperature
  • main.feels_like: Feels like temperature
  • main.humidity: Humidity percentage
  • weather[0].description: Weather description
  • wind.speed: Wind speed

We'll use these in the next step!


Part 5: Transform the Data

Raw JSON isn't user-friendly. Let's format it nicely.

Step 5.1: Add Code Node

  1. Click + after HTTP Request node
  2. Search for "Code"
  3. Select the node

Step 5.2: Write Transformation Code

In the Code editor, replace everything with:

Step 5.3: Understanding the Code

Line-by-line explanation:

  • $input.first(): Gets data from previous node (HTTP Request)
  • .json: Accesses the JSON data
  • data.main.temp: Temperature from API response
  • Math.round(): Rounds to nearest integer
  • Template literal (backticks) for multi-line string
  • ${variable}: Inserts variable values
  • Returns data in n8n format (array of objects with json property)

Step 5.4: Test the Transformation

  1. Click "Execute Node"
  2. View output in bottom panel
  3. You should see the formatted message

Expected Output:

Perfect! Now we have a nicely formatted message.


Part 6: Send Notification

Final step: Send the message to Slack (or email).

Option A: Slack Notification

Step 6.1: Add Slack Node

  1. Click + after Code node
  2. Search for "Slack"
  3. Select "Slack" node (not Slack Trigger)

Step 6.2: Configure Slack Connection

Authentication:

  1. Click "Create New Credential"
  2. Select "Slack OAuth2 API"
  3. Follow OAuth flow to connect your Slack workspace
  4. Authorize n8n access

OR use Webhook (simpler):

  1. In Slack node, select "Post Message" operation
  2. Instead of OAuth, use Webhook URL in credential
  3. Get webhook URL from api.slack.com/apps > Incoming Webhooks

Step 6.3: Configure Message

Resource: Message Operation: Post

Channel: #general (or create #weather channel)

Text (Expression Mode):

This uses the formatted message from the Code node!

Option B: Email Notification (Alternative)

If you prefer email over Slack:

Step 6.1: Add Email Node

  1. Click + after Code node
  2. Search for "Email" or "Gmail"
  3. Select "Gmail" (or SMTP for other email)

Step 6.2: Configure Email

To: your-email@example.com

Subject:

Email Type: Text

Text:

From Email: your-gmail@gmail.com

Authentication:

  • Connect Gmail via OAuth2
  • Or use App Password for SMTP

Step 6.4: Test the Notification

  1. Click "Execute Node" on Slack/Email node
  2. Check Slack channel or email inbox
  3. You should receive the formatted weather message!

Part 7: Test & Debug

Step 7.1: Test Complete Workflow

Now let's test the entire workflow end-to-end:

  1. Click "Execute Workflow" button (top bar)
  2. Watch each node execute in sequence:
    • Schedule Trigger ✓
    • HTTP Request ✓
    • Code ✓
    • Slack/Email ✓
  3. Check that notification was received

All nodes should have green checkmarks!

Step 7.2: Inspect Node Data

Click on each node to see data flow:

HTTP Request Node:

  • Click on node after execution
  • View "Output" tab
  • See raw API response

Code Node:

  • View "Input" tab: See data from HTTP Request
  • View "Output" tab: See formatted message

This helps you understand data transformation!

Step 7.3: Common Issues & Fixes

Issue: HTTP Request fails with 401 error

  • Fix: Check API key is correct
  • Fix: Ensure API key is activated (wait 10-20 minutes after signup)

Issue: Slack notification not received

  • Fix: Verify channel name is correct (include #)
  • Fix: Check bot has permission to post in channel
  • Fix: Re-authenticate Slack credential

Issue: Code node errors

  • Fix: Check syntax (missing brackets, quotes)
  • Fix: Verify variable names match API response
  • Fix: Add console.log() to debug:

Issue: Message formatting looks wrong

  • Fix: Check template literal backticks (not quotes)
  • Fix: Ensure line breaks (\n) are preserved

Part 8: Activate Your Workflow

Step 8.1: Save the Workflow

  1. Click "Save" button (top right)
  2. Confirm workflow name: "Weather Notification"
  3. Green toast notification confirms save

Step 8.2: Activate Workflow

  1. Click the toggle switch at top right: "Active"
  2. It should turn blue/green indicating active
  3. Workflow will now run automatically every day at 8 AM!

Step 8.3: Monitor Executions

View workflow runs:

  1. Click "Executions" in left sidebar
  2. See list of all workflow runs
  3. Click any execution to see details
  4. Check for errors or successes

Set up notifications for failures:

  • Go to Workflow Settings
  • Set "Error Workflow" to send alerts on failure

Step 8.4: Test Schedule (Optional)

To test without waiting until 8 AM:

  1. Deactivate workflow temporarily
  2. Change schedule to run in 2 minutes
  3. Activate and wait
  4. Check notification arrives
  5. Change schedule back to 8 AM

Troubleshooting

Problem: Workflow doesn't trigger at scheduled time

Diagnose:

  • Is workflow Active (toggle on)?
  • Check timezone settings (Workflow Settings)
  • Review execution history for errors

Solutions:

Problem: API returns empty data

Diagnose:

  • Test API in browser/Postman
  • Check API key is valid
  • Verify city name is correct

Solutions:

  • Use city ID instead of name: id=5391959 for San Francisco
  • Check API documentation: openweathermap.org/current
  • Try different city name format: "San Francisco,US"

Problem: Code node errors

Common Error: Cannot read property 'temp' of undefined

Solution:

Debugging technique:

View logs:

Problem: Notification not formatted correctly

Issue: Message shows escaped characters like \n

Solution: Use Slack blocks or ensure email client supports plain text formatting

Alternative Slack formatting:


Enhancing Your Workflow

Enhancement 1: Add Error Handling

Create Error Workflow:

  1. Create new workflow: "Weather Error Handler"

  2. Add nodes:

  3. In main workflow:

    • Settings → Error Workflow
    • Select "Weather Error Handler"

Error notification code:

Enhancement 2: Multiple Cities

Modify to send weather for multiple cities:

  1. After Schedule Trigger, add "Code" node:

  2. Update HTTP Request URL parameter:

    • Change q from "San Francisco" to ={{ $json.city }}

Now workflow loops through all cities!

Enhancement 3: Weather Alerts

Add conditional logic:

  1. After Code node (formatting), add "IF" node
  2. Condition:
  3. Route "true" to urgent alert (SMS, phone call)
  4. Route "false" to regular Slack message

Enhancement 4: Store Weather History

Track weather over time:

  1. Add "Google Sheets" or "PostgreSQL" node
  2. After Code node, branch to database
  3. Store: date, city, temp, conditions

Later, analyze trends!


Key Concepts Learned

✅ Nodes & Connections

  • Nodes are building blocks of workflows
  • Connections pass data between nodes
  • Green checkmarks indicate success

✅ Triggers

  • Schedule Trigger: runs on cron schedule
  • Other triggers: Webhook, Manual, Email, etc.
  • Active workflows run automatically

✅ Data Flow

  • $input: Access data from previous node
  • $json: The JSON payload
  • $node["Name"]: Access specific node data

✅ Expressions

  • ={{ ... }}: Expression mode
  • Access dynamic data in fields
  • JavaScript expressions allowed

✅ Code Nodes

  • Full JavaScript/Python environment
  • Transform data with custom logic
  • return [{ json: {...} }]: Return format

✅ HTTP Requests

  • Connect to any REST API
  • Query parameters, headers, authentication
  • GET, POST, PUT, DELETE methods

✅ Debugging

  • Execute individual nodes
  • Inspect input/output data
  • View execution history
  • Check logs for errors

Next Steps

Congratulations! 🎉

You've built your first n8n workflow! You now understand:

  • n8n fundamentals
  • API integration
  • Data transformation
  • Scheduling
  • Notifications

Continue Learning

Recommended Next Steps:

  1. Modify this workflow:

    • Change to your city
    • Add more weather details
    • Try different notification channels
  2. Build a variation:

    • Stock price alerts
    • News digest
    • RSS feed aggregator
    • Exchange rate monitor
  3. Complete Tutorial 2:

  4. Explore Use Cases:

    • Use Cases Guide
    • Find workflows for your industry
    • Apply patterns to your needs
  5. Read Best Practices:

Project Ideas (Practice)

Build these workflows to practice:

Easy:

  • Daily motivational quote
  • RSS to email digest
  • GitHub stars tracker
  • Currency converter alert

Medium:

  • Form submission to database
  • Customer email automation
  • Social media cross-posting
  • Backup automation

Challenging:

  • Multi-source data aggregation
  • Event-driven workflows
  • Complex approval flows
  • Integration hub for multiple apps

Workflow Export

Download this workflow:

[Export JSON link would go here]

Import it to compare with your build!

To import:

  1. Workflows → Import from File
  2. Select downloaded JSON
  3. Review and compare

Additional Resources

Official n8n Resources

Related Guides

APIs to Explore


Get Help

Stuck? Have questions?

Found this tutorial helpful? Share it with others learning n8n!

Need personalized help? Contact me about 1-on-1 tutoring or team training.


→ Ready for more? Continue to Tutorial 2: Data Pipeline Automation

Happy automating! 🚀

Stay in the loop

Get weekly insights on data engineering, analytics, and AI—delivered straight to your inbox.

No spam. Unsubscribe anytime.