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:
- Schedules automatic runs
- Sets niche keywords
- Generates a blog post topic
- Drafts a detailed post
- Fetches a relevant image
- Saves data to Google Sheets
- Handles errors
Step-by-Step Setup
Step 1: Create Workflow
- Log in to n8n.
- Click New Workflow.
Step 2: Add Schedule Trigger
- Click +, select Schedule Trigger.
- Set Interval to "Daily" (or "Every 5 minutes" for testing).
- Save.
Step 3: Set Niche Keywords
- Add Set node, connect to Schedule Trigger.
- 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.
)
- Test with Execute Node. Output:
{"interestField": "vegan recipes, plant-based cooking, healthy desserts"}
Step 4: Generate Blog Post Topic
- Add AI Agent node, connect to Set node.
- 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
- Credentials: Create new credentials.
- Test to confirm relevant topic.
Step 5: Draft Blog Post
- Add another AI Agent node, connect to first AI Agent.
- 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
- Test for valid HTML output.
Step 6: Fetch Image
- Add Pexels node, connect to second AI Agent.
- Configure:
- Credentials: Pexels API key
- Query:
{{$node["AI Agent"].json.title}}
- Max Results: 1
- Output Field:
imageUrl
- Test for valid image URL.
Step 7: Save to Google Sheets
- Add Google Sheets node, connect to Pexels.
- 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
- Title:
- Test to confirm data saves.
Step 8: Add Error Handling
- Add Error Trigger node, connect to all nodes.
- Add Send Email node:
- Message:
Workflow failed at {{$node["Error Trigger"].json.nodeName}}. Error: {{$node["Error Trigger"].json.errorMessage}}
- Message:
- Test by breaking a node (e.g., invalid API key).
Step 9: Test and Activate
- Click Execute Workflow.
- Verify Google Sheets data.
- Toggle Active.
Step 10: Publish to Google Blogger
- Review draft in Google Sheets.
- In Blogger, create post, use HTML view, paste Content column.
- Add
<img src="{{$GoogleSheet.ImageURL}}" alt="Blog image">
. - 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
Post a Comment