DEV Community

Grewup
Grewup

Posted on

Auto-Publish Daily Blog Posts Using n8n + OpenAI + WordPress (Full Workflow)

What this builds
A fully automated blog publishing pipeline. Every morning at 9 AM it fires without you touching anything:

Fetches a trending tech news article from the NewsData.io API
Sends the title and description to GPT-4.1 with a structured prompt
Gets back a unique blog post formatted in clean HTML
Parses and cleans the JSON response
Posts directly to your WordPress site via REST API

Zero manual steps after initial setup.

*Architecture overview
*

`Schedule Trigger (9 AM daily)
        ↓
HTTP Request → NewsData.io API (GET latest tech article)
        ↓
OpenAI node → GPT-4.1-nano (rewrite as blog post, return JSON)
        ↓
Code node → Parse JSON, extract title + content
        ↓
HTTP Request → WordPress REST API (POST new post, status: publish)`
Enter fullscreen mode Exit fullscreen mode

5 nodes. No custom server. Runs indefinitely.

Step 1 — Schedule Trigger

This is the heartbeat of the workflow. Create a new n8n workflow, add a Schedule Trigger node, and configure it:

`Mode:   Days
Hour:   9
Minute: 0`
Enter fullscreen mode Exit fullscreen mode

Every day at 9 AM, this node fires and passes execution to the next node. That's all it does — but without it, nothing runs.

Step 2 — Fetch news from NewsData.io

Add an HTTP Request node connected to the Schedule Trigger.

`
Method: GET
URL:    https://newsdata.io/api/1/news`
Enter fullscreen mode Exit fullscreen mode

Enable "Send Query Parameters" and add these five parameters:

The size: 1 parameter is intentional — you want one article per run, not a batch. Quality over volume for daily publishing.
What the response looks like:

`{
  "results": [
    {
      "title": "OpenAI Releases New Model Targeting Enterprise Workflows",
      "description": "The model focuses on structured output and tool use...",
      "link": "https://...",
      "pubDate": "2026-04-12 09:00:00"
    }
  ]
}`
Enter fullscreen mode Exit fullscreen mode

You'll reference results[0].title and results[0].description in the next step.

Step 3 — OpenAI node (the rewrite engine)

Add an OpenAI node and connect your API key. The prompt structure here is the most important part of the entire workflow — it determines the quality and format of every post that gets published.
System message:

`

You are an expert blog writer who creates engaging, original content.
You excel at transforming news into interesting articles without plagiarism.
`

User message:

`Write a completely original blog post about this news:
Title: {{ $json.results[0].title }}
Description: {{ $json.results[0].description }}

Requirements:
- Create a unique and engaging title
- Write EXACTLY 5 separate paragraphs (each in its own <p> tag)
- Include your own analysis and perspective
- Do NOT copy phrases from the original source
- End with a thoughtful conclusion

Format the response as clean JSON without backticks:
{
  "title": "Your creative blog title",
  "content": "The full blog post content with HTML formatting including separate <p> tags for each paragraph"
}`
Enter fullscreen mode Exit fullscreen mode

Model: gpt-4.1-nano-2025-04-14
Why this model specifically? It's fast, cheap (~$0.001 per post at this prompt length), and produces quality output for structured writing tasks. GPT-4o is overkill here — you're rewriting news summaries, not solving reasoning problems.
Critical: The prompt explicitly requests JSON without backticks. OpenAI sometimes wraps JSON in json ... fences. The next node handles this if it happens, but prompting for clean output reduces the edge cases.

Step 4 — Code node (parse the response)

OpenAI returns text. WordPress needs structured data. This node bridges them.
Add a Code node after OpenAI, set Language to JavaScript, and paste this:

`const response = items[0].json.message.content;
const parsed = JSON.parse(response);

return [
  {
    json: {
      title: parsed.title,
      content: parsed.content
    }
  }
];`
Enter fullscreen mode Exit fullscreen mode

What this does:

Line 1: grabs the raw text content from the OpenAI response object
Line 2: converts that text string into an actual JavaScript object
Lines 4–9: returns only the two fields WordPress needs — title and content

If JSON.parse throws: OpenAI occasionally wraps output in markdown fences despite instructions. Add this defensive version:

`const response = items[0].json.message.content;
const clean = response.replace(/```
{% endraw %}
json|
{% raw %}
```/g, '').trim();
const parsed = JSON.parse(clean);

return [
  {
    json: {
      title: parsed.title,
      content: parsed.content
    }
  }
];`
Enter fullscreen mode Exit fullscreen mode

Execute the node and check the output panel. You should see a title string and a content string with HTML

tags. If you see an error, the OpenAI response format is the issue — check what the raw content field actually contains.

Step 5 — WordPress HTTP Request (publish the post)

Add a second HTTP Request node. This one is a POST, not a GET.

`Method:         POST
URL:            https://yourdomain.com/wp-json/wp/v2/posts
Authentication: Predefined Credential Type → WordPress API
`
Enter fullscreen mode Exit fullscreen mode

Getting your WordPress application password:

  1. WordPress admin → Users → Your profile
  2. Scroll to "Application Passwords" section
  3. Enter a name (e.g., "n8n automation") → Add New Application Password
  4. Copy the generated password — you won't see it again
  5. In n8n credential: enter your WordPress username + this application password (not your login password)

Testing the full workflow
Before activating:

Click "Execute Workflow" from the Schedule Trigger
Watch each node execute in sequence — green checkmarks mean success
Check your WordPress admin → Posts → should see a new published post
Read the post — verify it's coherent, original-looking content with proper HTML formatting

The first test run usually surfaces one of three issues (and their fixes):

OpenAI node errors with 429 (rate limit): You've exceeded your API quota. Add credits to your OpenAI account.
WordPress returns 401 Unauthorized: The application password is wrong, or you used your login password instead of the generated application password. Regenerate it.

Code node throws SyntaxError: Unexpected token: OpenAI wrapped the JSON in backtick fences. Use the defensive parsing version from Step 4.

NewsData.io returns empty results array: Your API key is invalid or the free tier rate limit was hit (200 requests/day). Check your NewsData.io dashboard.

Activating and monitoring
Once the test passes, toggle the workflow active in the top-right corner. The toggle turns blue.

Check the Executions tab daily for the first week. Each execution log shows you exactly what data passed through each node and where any failures occurred. n8n retries failed executions automatically by default.

Optional: add error handling
Add an Error Trigger node to catch any workflow failures and send yourself a Telegram or email alert. This way you know immediately if an API key expires or a service is down.

What to build next
Once this runs cleanly for a week:

Swap technology for business, health, or any NewsData.io category to run niche-specific blogs in parallel
Add a WordPress category ID parameter to the POST body to auto-categorize posts
Add a second OpenAI call before publishing to generate an SEO meta description
Replace the Schedule Trigger with a manual trigger and add a Telegram bot interface — send the bot a topic, get a blog post published in 30 seconds

Full setup guide with every screenshot at elevoras.com.
Built a variation of this? Drop your node config in the comments — especially interested in anyone who's added image generation to the pipeline.

Top comments (0)