How I Automated My Daily Needs Using n8n
As someone who constantly strives to automate repetitive tasks, I’ve always been on the lookout for tools that simplify workflows. Automating daily needs often required me to code from scratch, set up a boilerplate, and manage scripts. Recently, while exploring the Fediverse, I discovered n8n, a powerful workflow automation tool. Intrigued, I decided to try it, and it turned out to be a game-changer.
Setting Up n8n on Docker
Since Docker is my go-to tool for deployments, getting started with n8n was a breeze. I deployed it on my self-hosted Fedora Linux system, and the process was straightforward.
Here’s the Docker Compose configuration I used:
This setup requires configuring a few environment variables like NODE_ENV=production
, N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true
, N8N_RUNNERS_ENABLED=true
, N8N_EDITOR_BASE_URL=${DOMAIN_NAME}
, N8N_HOST=${DOMAIN_NAME}
, and WEBHOOK_URL=https://${DOMAIN_NAME}/
. Once configured, I spun it up with docker compose up -d
, and just like that, n8n was ready to go.
My Use Case: Automating Posts Across Fediverse Platforms
I regularly use threads, which has Fediverse integration, and mastodon for social media engagement. However, manually posting or reposting content across these platforms felt tedious. The idea of keeping all my activity centralized appealed to me, and this is where n8n came into play.
With n8n, I automated the process of reposting my threads updates to my mastodon profile. This setup ensures that any post I create in threads gets automatically boosted on mastodon. Here’s how I did it:
How it works
The workflow runs on a scheduled trigger and retrieves recent posts from a specified Fediverse account, such as your Threads.net account. It uses a JavaScript filter to identify posts from the current day and then automatically boosts or reshares them to your selected Mastodon profile.
Preconditions
- You need a Mastodon account with developer access.
- Identify a threads.com or other Fediverse account which you want to boost.
- Basic familiarity with APIs and setting up credentials in n8n.
Setup Steps
Step 1: Create a Developer Application on Mastodon
- Log in to your Mastodon account and navigate to Preferences > Development > New Application.
- Fill out the required information and create your application.
- Set Scopes to atleast
read, profile, write:statuses
. - Click submit.
- Note down the access token generated for this application.
Step 2: Get the Account ID
Use the following command to retrieve the account ID for the profile you want to boost:
1
curl -s "https://mastodon.social/api/v1/accounts/lookup?acct=<ACCOUNTNAME>"
Alternatively, paste the URL into a GET node on n8n.
From the returned JSON, copy the
"id"
field value (e.g.,{"id":"110564198672505618", ...}
).
Step 3: Update the “Get Statuses” Node
Replace
ACCOUNTID
in the URL field with the ID you retrieved in Step 2:1
https://mastodon.social/api/v1/accounts/<ACCOUNTID>/statuses
Step 4: Configure the “Boost Statuses” Node
Authentication type will already be set to Header Auth.
- Grab the access token from Step 1.
- In the Credential for Header Auth field, create a new credential.
- Click the pencil icon in the top-left corner to name your credential.
- In the
Name
field, enterAuthorization
. - In the
Value
field, enterBearer <YOUR_MASTODON_ACCESS_TOKEN>
. (Note: there is a space after “Bearer.”) - Save the credential, and it should automatically be selected as your Header Auth.
Step 5: Test the Workflow
- Run the workflow to ensure everything is set up correctly.
- Adjust filters or parameters as needed for your specific use case.
Customization Guidance
- Replace
mastodon.social
with your own Mastodon domain if you’re using a self-hosted instance. - Adjust the JavaScript filter logic to meet your specific needs (e.g., filtering by hashtags or keywords).
- For enhanced security, store the access token as an n8n credential. Embedding it directly in the URL is ++not recommended++.
Notes
- This workflow is designed to work with any Mastodon domain.
- Ensure your Mastodon account has appropriate permissions for boosting posts.
By following these steps, you can automate your Fediverse engagement and focus on creating meaningful content while the workflow handles the rest!
Conclusion
n8n has revolutionized how I approach automation. Tasks that once demanded hours of scripting are now simplified into configurable diagrams. Whether you’re an automation enthusiast or a developer looking for efficiency, n8n is worth exploring. Check out the templates available on n8n.io, and take your automation game to the next level.
If you’re like me—someone who believes every repetitive task is an opportunity for automation—you’ll appreciate the versatility and simplicity that n8n brings to the table.