Effortlessly Generate and Publish Content with AI and Automation

Discover how n8n, coupled with AI tools like OpenRouter and the WordPress REST API, can revolutionize your content creation process. Automate the generation and publishing of blog posts, making your workflow smoother and more efficient.

Building Your Automated Content Pipeline with n8n

n8n is a digital workflow builder that connects apps like LEGO bricks for automation. It integrates services to create blog posts automatically, using AI for content generation and WordPress REST API for publishing.

Assumptions/Prereqs

  • Docker installed: docker --version
  • WordPress site with REST API enabled and app password
  • Basic terminal access

Setup Steps

  1. Run n8n:
    docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n
  2. Open http://localhost:5678 in browser, set up admin account.
  3. Create workflow: Click New > Add Schedule Trigger node.
  4. Add AI Agent node: Connect to OpenAI, prompt Write a blog post about [topic].
  5. Add WordPress node: Set site URL, app credentials, action Create Post.
  6. Connect nodes, click Execute Workflow.

Verify

n8n executions list --json | grep success

Check WordPress posts.

Common Issues

  • Docker port busy: docker stop n8n; docker rm n8n
  • AI auth fail: Verify OpenAI API key in node credentials.
  • WP 401: Regenerate app password in WP admin.

AI Content Generation and Seamless Publishing

Assumptions/Prereqs:

  • n8n installed from previous chapter
  • OpenRouter API key from openrouter.ai
  • WordPress site with REST API enabled + Application Password
  • Basic n8n workflow knowledge

Step-by-Step:

  1. Add OpenRouter (HTTP Request node):
    POST https://openrouter.ai/api/v1/chat/completions
    Headers:
    Authorization: Bearer YOUR_OPENROUTER_KEY
    Content-Type: application/json
    Body:
    {
      "model": "openai/gpt-4o-mini",
      "messages": [{"role": "user", "content": "Write blog post about Linux automation"}]
    }
  2. Parse JSON response: Use Code node:
    return [{json: {title: $json.choices[0].message.content.split('\n')[0], content: $json.choices[0].message.content}}];
  3. WordPress Publish (HTTP Request):
    POST https://yoursite.com/wp-json/wp/v2/posts
    Headers:
    Authorization: Basic base64(username:application_password)
    Content-Type: application/json
    Body:
    {
      "title": "{{ $json.title }}",
      "content": "{{ $json.content }}",
      "status": "publish"
    }

Verification:

curl -u username:app_pass https://yoursite.com/wp-json/wp/v2/posts?per_page=1

Common Failures + Fixes:

  • 401 Unauthorized: Check WP Application Password format
  • 429 Rate Limit: Add IF node + Wait (60s) + retry
  • OpenRouter 402: Top up credits at openrouter.ai
  • Empty content: Add error notification (Email/Slack node)

Image Integration: Add DALL-E via OpenRouter same endpoint, model: openai/dall-e-3, save URL to WP featured_media.

Automate AI→WP publishing. Experiment now!


Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *