Cross-posting content automatically with n8n ✍️

Amudhan
Amudhan
Jun 29 · 8 min read

Blogging isn’t just about writing quality content, but also ensuring that it reaches as many members of your audience as possible. This means that bloggers have to post an article multiple times on different platforms. This often entails ensuring that the formatting and layouts are consistent across platforms, which tends to be a time consuming (and exhausting) ordeal.

Image for post
Image for post
Automating cross-posting blog posts using n8n

Automating these processes can save large amounts of time and effort, allowing bloggers to reclaim time to focus on what they do best — writing. This tutorial will teach you how to post blog posts to multiple blogging platforms automatically.

In this tutorial, we’re going to create and store all our posts in one central platform — Strapi. It is a headless CMS which will store all our content. We will use n8n to create a workflow that will take content from Strapi using webhooks and create posts on Medium and Dev.to using their REST APIs. Strapi supports post creation through markdown formatting, which will help maintain the layouts of articles across platforms.

1. Getting ready

If you get stuck, or prefer to not use Docker, you can check out alternative install methods here (strapi setup guide).

Setting up Strapi

version: '3'
services:
strapi:
image: strapi/strapi
volumes:
- ./:/srv/app
ports:
- '1337:1337'

Then, start the service by running:

docker-compose up -d

Setting up n8n

docker run -it — rm \
— name n8n \
-p 5678:5678 \
-v ~/.n8n:/root/.n8n \
n8nio/n8n \
n8n start — tunnel

Note: This is only meant for local development and testing. For information on how to deploy n8n in a production environment, please refer to the n8n setup guide.

Make sure that all the services have been started using docker ps. You should be able to see two running containers, one for Strapi and one for n8n.

You can also follow along this guide by copying the workflow from n8n.io and making appropriate changes at each step.

2. Setting up a Webhook node

Add a new node by clicking the + button on the top right of the Editor UI. Under the Triggers section, select the Webhook node. Then, select the POST option for HTTP Method. Enter a webhook Path. This can be any name you want.

Now, save the workflow. This activates the webhook. Finally, copy the test webhook URL (we will need this later). Here’s a GIF of me following the steps mentioned above.

Image for post
Image for post
Adding a Webhook node to the workflow

3. Creating a collection in Strapi and setting up the webhook

Create a collection with the fields for a blogpost:

  1. Title — Short text
  2. Post Datetime — Datetime
  3. Post Content — Rich text
  4. Feature Image — Single media
  5. Tag — Enumeration
Image for post
Image for post
Creating a collection in Strapi

Head over to the settings section and set up a webhook for a Create Entry event of your new collection. Paste the n8n webhook URL you copied from the previous step. Now, save your changes by clicking on the Save button.

Image for post
Image for post
Adding a webhook in Strapi

4. Creating POST requests for the Dev.to API

Let’s start with Dev.to as an example. Go ahead and obtain an API Key from the Settings section of your account.

First, create a sample post and retrieve the data model from Strapi, by clicking on the Execute Node button and then creating a new sample post in Strapi. It should look something like the image below.

Image for post
Image for post
Sample data retrieved from Strapi

Note: You will need to use the test webhook to be able to view the data that n8n processes as shown above. The production node does not display retrieved data in the workflow editor. We recommend that you use the test webhook to configure the workflow.

Next, we need to send the data to Dev.to via their REST API. One of the ways to do this is by using a POST request. POST requests are a type of web requests that can send data to a server by including it as a ‘payload’. In n8n, POST requests can be created and used via the HTTP Request node.

Now, using the HTTP Request node, we can send the data to dev.to. Set the Authentication to ‘Header Auth’ and use the API key from your Dev.to account (you can create one in Settings > Account) to authenticate. Set JSON/RAW Parameters to true (turn the switch on). Set the request method as POST and paste the API endpoint in the URL (https://dev.to/api/articles in our case). Using the Add Option menu, select Body Content-Type and set it to ‘JSON’.

The final step to create the node is to add the request body, or the payload, in JSON format. This will contain all the data that is needed to make a post. To dynamically change the data based on previous nodes, we will use the powerful “Add expression” tool. You can access this by clicking the ⚙️ (gears) icon and choosing Add Expression.

Now, select the following variable:

Nodes > Webhook > Output Data > JSON > Entry > Title

Here’s an example of me adding an expression to a node.

Image for post
Image for post
Adding an expression to a node

Having previously read through Dev.to’s API documentation, I chose all the information that I wanted to send to Dev.to and encoded it as JSON.

{
"article": {
"title": "Post Title",
"published": true,
"body_markdown": "I love n8n!",
"tags": [
"TutorialSample", "Guide", "Instructional",
],
"series": "n8n Guides",
"canonical_url": "https://your-strapi.url/postname"
}
}

For consistency, I chose to only include the fields that both Medium and Dev.to would support.

If you want to include or exclude information, please refer to Dev.to API reference.

Next, test this node by clicking Execute Node to run this node. Then, head over to Dev.to and check if a new post has been created. If you see a new post; it means you’ve set this up correctly.

Here’s a GIF of me following the steps mentioned above.

Image for post
Image for post
Adding an HTTP Request node for Dev.to

5. Creating POST requests for the Medium API

First, we begin by changing the endpoint URL by adding in your authorid.To do this, you need to find your authorid (Refer: https://github.com/Medium/medium-api-docs#33-posts) and then replace it in the following:

https://api.medium.com/v1/users/{{authorId}}/posts

Next, you need to email yourfriends@medium.com to gain API access (Refer:https://github.com/Medium/medium-api-docs#22-self-issued-access-tokens). Once you have API access, create an API token and copy it (we will need this in the next step).

Let’s create the node. Set the Authentication to ‘Header Auth’ and add the Key as ‘Bearer’ and the password as the API key you obtained for authentication. This time, instead of writing the JSON payload ourselves we use the built in menu-based options to add JSON Request Parameters. I chose to use a basic set of parameters, but you can find a list of all supported parameters here and change them up according to your preferences.

Here’s a list of body parameters I used:

  1. title — using data from the webhook node
  2. contentFormat — markdown
  3. content — using data from the webhook node
  4. tags — using data from the webhook node
  5. canonicalUrl — using data from the webhook node
  6. publishStatus — public

You can add the parameters in the Body Parameters section using the names above and mapping the data from the Strapi Webhook node.

Then, test this node by clicking Execute Node to run this node. Then, head over to Medium to check if a new post has been created. If you see a new post; it means you’ve set this up correctly. Continue to the next step.

Here’s a GIF of how I set up my HTTP Request node for Medium.

Image for post
Image for post
Adding an HTTP Request node for Medium

6. Executing the workflow

Create a post in Strapi and save it. Head over to Dev.to and Medium to check if the blog posts have been created (it might take a few seconds).

Here’s a GIF of me executing my workflow.

Image for post
Image for post
Testing the workflow by creating a new post on Strapi

The post has shown up with the correct content and tags on both platforms. We’ve set up n8n to cross-post content to both Medium and Dev.to.

And, that’s it! Congratulations, you have just automated cross-posting across blogging platforms 🎉

Adding more platforms

You can also automate cross-platform updation and deletion of posts; making Strapi a powerful tool to manage and deliver your content across several online platforms.

You can also experiment in a similar manner with social networking workflows such as twitter, announcing a new blog post via a tweet. Such companion social media pages for blogs ensure that your content reaches even wider audiences.

Conclusion

Writing is a creative industry and everyone has their own style and way of doing things — a workflow that they prefer. n8n can help automate the repetitive tasks of your workflow. Which parts of your daily life are repetitive and tedious? What will you automate?

In case you’ve run into an issue while following the tutorial, feel free to reach out to me on LinkedIn or ask for help on our forum 💙

n8n.io

Turn ideas into reality

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store