Automate Blog Post Publishing to Medium, Dev.to, and Ghost Using n8n

admin1234 Avatar

## Introduction

For marketing teams in startups and tech companies, maintaining a consistent and widespread content presence is crucial for brand visibility, lead generation, and community engagement. However, manually publishing blog posts across multiple platforms like Medium, Dev.to, and Ghost can be time-consuming and error-prone. An effective automation workflow not only saves time but also ensures consistency of content and metadata across channels.

This article provides a comprehensive, step-by-step tutorial on how to build a seamless blog post publishing automation using n8n, an open-source workflow automation tool. The workflow will allow you to publish a blog post simultaneously to Medium, Dev.to, and a self-hosted Ghost blog with a single trigger. This solution benefits marketing teams, content managers, and automation engineers looking to streamline multi-channel content distribution.

## Tools and Services Integrated

– **n8n:** open-source workflow automation tool
– **Medium API:** to publish posts on Medium
– **Dev.to API:** to publish posts on Dev.to
– **Ghost Admin API:** to publish posts on a Ghost blog
– **Google Drive or Google Docs:** (Optional) Source for blog content
– **Slack:** (Optional) Notifications on success or failure

## Use Case Overview and Workflow Logic

**Problem**: Publishing content manually across multiple blogging platforms is inefficient and error-prone.

**Solution**: Automate the process so a single piece of content can be published to Medium, Dev.to, and Ghost simultaneously.

**Who benefits**: Marketing teams, content operations, automation engineers, and startup CTOs managing content publication pipelines.

**Workflow Summary:**

1. **Trigger:** Manual trigger or scheduled trigger to initiate the workflow
2. **Fetch Content:** Retrieve blog post content from Google Docs (or input directly)
3. **Transform Content:** Format content and metadata to platform-specific requirements
4. **Publish on Medium:** Use Medium API node
5. **Publish on Dev.to:** Use HTTP Request node with Dev.to API
6. **Publish on Ghost:** Use HTTP Request node with Ghost Admin API
7. **Notify:** Send Slack notification of success or failure

## Step-by-Step Technical Tutorial

### Prerequisites

– n8n installed and running (local or cloud)
– Accounts with API access setup for Medium, Dev.to, and Ghost
– API keys or tokens ready
– Google account with blog post in Docs or content ready
– Slack webhook URL (optional)

### Step 1: Configure n8n Workflow Trigger

**Options:**
– **Manual Trigger node:** start workflow on demand
– **Cron node:** schedule publishing

For this guide, use the **Manual Trigger** node to test effectively.

### Step 2: Retrieve Blog Content

Option 1: **Google Docs Integration**
– Use Google Docs node to fetch content
– Configure OAuth2 credentials for Google Drive access
– Locate the document ID of the blog post
– Fetch content in plain text or HTML format

Option 2: **Static Data**
– Use a **Set node** to define blog content, title, tags, and metadata manually for testing

Example fields:
– title
– content (HTML or Markdown)
– tags (array)
– canonicalUrl (optional)

### Step 3: Format Content for Each Platform

Each platform expects slightly different content formatting:

– **Medium** accepts HTML content, plus metadata like title, tags, publish status
– **Dev.to** expects Markdown content, tags as comma-separated string
– **Ghost** accepts HTML for the post body, JSON for metadata

Use **Function nodes** as needed to transform content appropriately.

Example function to convert array of tags to comma-separated string:
“`javascript
return [{ json: { tagsString: $json.tags.join(“,”) } }];
“`

### Step 4: Publish to Medium

– Use **HTTP Request node** (since as of now n8n may not have a native Medium node)

**API Endpoint:** `POST https://api.medium.com/v1/users/{userId}/posts`

**Headers:**
– Authorization: Bearer YOUR_MEDIUM_TOKEN
– Content-Type: application/json

**Body:**

“`json
{
“title”: “{{$json[“title”]}}”,
“contentFormat”: “html”,
“content”: “{{$json[“content”]}}”,
“publishStatus”: “public”,
“tags”: {{$json[“tags”]}},
“canonicalUrl”: “{{$json[“canonicalUrl”] || null}}”
}
“`

**How to get userId:**
– Make a GET request to `https://api.medium.com/v1/me` with your token to find your userId.

### Step 5: Publish to Dev.to

Dev.to requires an API key generated from your account.

– Use **HTTP Request node**

**API Endpoint:** `POST https://dev.to/api/articles`

**Headers:**
– api-key: YOUR_DEVTO_API_KEY
– Content-Type: application/json

**Body:**

“`json
{
“article”: {
“title”: “{{$json[“title”]}}”,
“body_markdown”: “{{$json[“contentMarkdown”]}}”,
“tags”: “{{$json[“tagsString”]}}”,
“published”: true
}
}
“`

Note: Dev.to requires Markdown format. Transform HTML to Markdown if necessary using community libraries or n8n Function node.

### Step 6: Publish to Ghost

Ghost requires Admin API access with an Admin API Key.

– Use **HTTP Request node**

**API Endpoint:** `POST https://YOUR_GHOST_URL/ghost/api/v3/admin/posts/`

**Authentication:** A JWT token generated from the Admin API Key (requires a bit more setup). Alternatively, use n8n’s HTTP Request with proper headers.

**Body:**

“`json
{
“posts”: [{
“title”: “{{$json[“title”]}}”,
“html”: “{{$json[“content”]}}”,
“status”: “published”,
“tags”: [
{ “name”: “tag1” },
{ “name”: “tag2” }
]
}]
}
“`

**Steps to generate JWT:**
– Use a Function node with Node.js JWT library (or use external script) to generate token from key and id.

Example JWT generation function (simplified):
“`javascript
const jwt = require(‘jsonwebtoken’);

const token = jwt.sign({}, ‘YOUR_ADMIN_API_SECRET’, {
keyid: ‘YOUR_ADMIN_API_KEY_ID’,
algorithm: ‘HS256’,
expiresIn: ‘5m’,
audience: ‘/v3/admin/’
});

return [{ json: { token } }];
“`

Pass this token in the `Authorization: Ghost ${token}` header.

### Step 7: Send Slack Notifications (Optional)

Add a **Slack node** to send notifications on success or failure.

– Define message templates
– Include status, URLs of published posts, or error messages

### Step 8: Error Handling and Retries

– Add **Error Trigger node** or configure retry settings
– Use **IF nodes** to verify API response status codes
– Log errors to a Google Sheet or send notification

## Common Errors and Tips for Robustness

– **Authentication Failures:** Verify tokens are valid and permissions are granted.
– **Rate Limits:** Respect API rate limits; implement wait nodes or throttling.
– **Content Formatting Errors:** Ensure Markdown/HTML formats match platform requirements.
– **Network Failures:** Add retries and error handling nodes.
– **API Changes:** APIs evolve; monitor changelogs and update workflow.

Tips:
– Use environment variables or n8n Credentials feature for API keys.
– Modularize workflow to isolate errors.
– Log all API responses for debugging.
– Schedule workflows during low-traffic periods if possible.

## Scaling and Adaptation

– **Add Platforms:** Extend workflow to other platforms (WordPress, LinkedIn).
– **Input Sources:** Integrate with CMS or content planning tools to fetch new posts.
– **Localization:** Add steps for translating content before publishing.
– **Approval Process:** Insert review steps with notifications before publishing.
– **Analytics Integration:** Post-publish, retrieve stats and log for reporting.

n8n’s visual interface makes adding these steps straightforward.

## Summary

This tutorial covered how to build a powerful, multi-platform blog publishing automation with n8n, enabling marketing teams to publish simultaneously on Medium, Dev.to, and Ghost. By consolidating publishing tasks, teams save time, reduce errors, and maintain content consistency.

Automating content distribution is essential in a lean startup environment where operational efficiency drives growth. Leveraging APIs and n8n’s flexibility, your team can easily scale publishing workflows and integrate additional platforms or advanced features.

## Bonus Tip: Version Control Your Content

To enhance your workflow, store your blog drafts and metadata in version-controlled repositories (e.g., GitHub). Combine with n8n’s Git nodes or webhooks to trigger automated publishing upon merges or tags, ensuring publication of only approved content.

Feel free to adapt this workflow to your startup’s specific requirements and continuously improve as your multi-channel marketing evolves.