Automate Blog Content Creation with n8n and Grok 3 API

Automate Blog Content Creation with n8n and Grok 3 API

Introduction

n8n is an open-source automation tool that connects apps to streamline tasks. This tutorial guides you through creating a workflow to automate blog post creation for Google Blogger using the Grok 3 API for content generation, Pexels for images, and Google Sheets for storage. The workflow ensures niche-relevant content and uses n8n’s free tier.

Prerequisites

  • n8n account (free at n8n.io)
  • Grok API key (x.ai/api)
  • Pexels API key (pexels.com/api)
  • Google account for Sheets and Blogger
  • Google Sheet with columns: Title, Content, Meta Description, Image URL, Status

Workflow Overview

The workflow:

  1. Schedules automatic runs
  2. Sets niche keywords
  3. Generates a blog post topic
  4. Drafts a detailed post
  5. Fetches a relevant image
  6. Saves data to Google Sheets
  7. Handles errors

Step-by-Step Setup

Step 1: Create Workflow

  1. Log in to n8n.
  2. Click New Workflow.

Step 2: Add Schedule Trigger

  1. Click +, select Schedule Trigger.
  2. Set Interval to "Daily" (or "Every 5 minutes" for testing).
  3. Save.

Step 3: Set Niche Keywords

  1. Add Set node, connect to Schedule Trigger.
  2. Configure:
    • Add Value > String.
    • Name: interestField
    • Value: Keywords (e.g., vegan recipes, plant-based cooking, healthy desserts) or prompt (e.g., Generate content for a vegan food blog.)
  3. Test with Execute Node. Output: {"interestField": "vegan recipes, plant-based cooking, healthy desserts"}

Step 4: Generate Blog Post Topic

  1. Add AI Agent node, connect to Set node.
  2. Configure:
    • Credentials: Create new credentials.
      • Type: Custom API
      • URL: https://api.x.ai/v1
      • API Key: Grok API key
    • Model: grok-3
    • System Message:
      You are a content assistant. Using the interest field ({{$node["Set"].json.interestField}}), suggest one blog post topic. Output only the topic title.
      Example: 5 Easy Vegan Dessert Recipes
    • Temperature: 0.7
    • Max Tokens: 50
    • Output Field: title
  3. Test to confirm relevant topic.

Step 5: Draft Blog Post

  1. Add another AI Agent node, connect to first AI Agent.
  2. Configure:
    • Use same Grok credentials.
    • Model: grok-3
    • System Message:
      You are a blog writer. Using the topic ({{$node["AI Agent"].json.title}}) and interest field ({{$node["Set"].json.interestField}}), write a blog post (up to 500 words) with an H1 title, at least two H2 sections, and a meta description. Format in clean HTML.
      Example:

      5 Easy Vegan Dessert Recipes

      Chocolate Avocado Mousse

      Blend avocados and cocoa...

      Coconut Chia Pudding

      A refreshing treat...

    • Temperature: 0.8
    • Max Tokens: 1000
    • Presence Penalty: 0.5
    • Output Fields: title, content, metaDescription
  3. Test for valid HTML output.

Step 6: Fetch Image

  1. Add Pexels node, connect to second AI Agent.
  2. Configure:
    • Credentials: Pexels API key
    • Query: {{$node["AI Agent"].json.title}}
    • Max Results: 1
    • Output Field: imageUrl
  3. Test for valid image URL.

Step 7: Save to Google Sheets

  1. Add Google Sheets node, connect to Pexels.
  2. Configure:
    • Credentials: Google Sheets OAuth2
    • Spreadsheet: Select "BlogDrafts"
    • Fields:
      • Title: {{$node["AI Agent 2"].json.title}}
      • Content: {{$node["AI Agent 2"].json.content}}
      • Meta Description: {{$node["AI Agent 2"].json.metaDescription}}
      • Image URL: {{$node["Pexels"].json.imageUrl}}
      • Status: Draft
  3. Test to confirm data saves.

Step 8: Add Error Handling

  1. Add Error Trigger node, connect to all nodes.
  2. Add Send Email node:
    • Message: Workflow failed at {{$node["Error Trigger"].json.nodeName}}. Error: {{$node["Error Trigger"].json.errorMessage}}
  3. Test by breaking a node (e.g., invalid API key).

Step 9: Test and Activate

  1. Click Execute Workflow.
  2. Verify Google Sheets data.
  3. Toggle Active.

Step 10: Publish to Google Blogger

  1. Review draft in Google Sheets.
  2. In Blogger, create post, use HTML view, paste Content column.
  3. Add <img src="{{$GoogleSheet.ImageURL}}" alt="Blog image">.
  4. Publish.

Workflow Diagram

[Schedule Trigger] --> [Set Keywords] --> [AI Agent: Topic] --> [AI Agent: Draft] --> [Pexels] --> [Google Sheets]
   (Daily)            (Niche focus)      (Topic)            (Post)           (Image)      (Saves draft)
        |                                                                |
        +------------------> [Error Trigger] --> [Email] (Notifies) <----+
    

Troubleshooting

  • Grok API Issues: Verify key at x.ai/api.
  • Sheets Access: Check OAuth2 permissions.
  • Irrelevant Content: Refine keywords (e.g., vegan desserts).
  • No Image: Use broader Pexels query.
  • Workflow Failure: Ensure Active toggle is on.

Tips

  • Use specific keywords (e.g., vegan desserts, gluten-free baking).
  • Review AI output for tone.
  • Check Pexels image relevance.
  • Explore n8n’s blog.

Conclusion

This n8n workflow automates blog content creation with Grok 3 API, Pexels, and Google Sheets, ensuring niche-relevant posts for Google Blogger. Using n8n’s free tier, you can streamline content creation efficiently.

Comments

Popular posts from this blog

Risk Management for Data Scientists in Insurance and Finance

Building and Deploying a Recommender System on Kubeflow with KServe

CrewAI vs LangGraph: A Simple Guide to Multi-Agent Frameworks