Automate AI News Posting to X Using n8n and Perplexity API

Discover how to automatically fetch and post the latest AI news on X (Twitter) using n8n and the Perplexity AI API. This workflow saves you hours each week by delivering concise, accurate tech news headlines directly to your audience.
scheduleTrigger
httpRequest
twitter
+1
Workflow Identifier: 1925
NODES in Use: Schedule Trigger, Set, HTTP Request, Twitter

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

Opening Problem Statement

Meet Sarah, a social media manager at a fast-growing AI startup. Every day, she spends hours scouring the internet for the latest developments in artificial intelligence to share timely updates on her company’s X (formerly Twitter) account. The process is tedious, error-prone, and consumes valuable time she could spend on strategy or engagement.

With the rapid pace of AI advancements, missing a key update could mean lost visibility and engagement, while manually crafting posts often leads to inconsistent messaging and delays. Sarah needs a reliable way to automate discovering and posting the latest AI news directly to X, ensuring her followers stay informed without her daily intervention.

What This Automation Does

This n8n workflow uses the Perplexity AI API to search for the latest news in artificial intelligence and automatically posts a concise headline with a direct link to X. Here’s what happens when you run this automation:

  • The workflow triggers every 21 hours at a random minute, ensuring regular yet unpredictable posting times.
  • It sets a predefined search query: “What’s the latest news in artificial intelligence?” to retrieve fresh AI news.
  • The workflow calls the Perplexity AI endpoint with a carefully crafted prompt that instructs the AI to return a single, precise news headline plus a direct article link suitable for X’s character limits.
  • It extracts the AI-generated content and posts it as a tweet on your connected X account using secure OAuth2 credentials.
  • The whole process is hands-free, running reliably in the background to keep your audience informed.
  • You save hours weekly that were previously spent manually searching, summarizing, and posting news.

Prerequisites ⚙️

  • n8n account set up (cloud or self-hosted). For easy self-hosting, consider a provider like Hostinger.
  • Perplexity AI API key (for querying news articles).
  • X (Twitter) developer account with OAuth2 API credentials connected to n8n.

Step-by-Step Guide

1. Configure the Schedule Trigger to Run Periodically

In the n8n editor, locate the Schedule Trigger node. Set it to trigger every 21 hours with a random minute between 0 and 59 to spread out post times slightly.

Navigation: Click the Schedule Trigger node → under “Rule,” select “Hours Interval” → enter 21 hours → for “triggerAtMinute” paste =Math.floor(Math.random() * 60).

Once saved, this setup ensures your automation runs roughly once per day but avoids exact repetition times.

Common Mistake: Forgetting to include the random minute formula results in posts always happening at the exact same minute, which can look robotic.

2. Define the Search Query

Next, open the searchQuery Set node. Here, a static string assignment defines the question sent to Perplexity AI: What's the latest news in artificial intelligence?

Navigation: Click the Set node → under Assignments, enter searchInput as the name and the query string as value.

By fixing the input query, you keep the news topic tightly focused.

Common Mistake: Leaving this blank or putting a very broad term dilutes the quality of retrieved news.

3. Insert Your Perplexity API Key

Before calling the API, the workflow sets your API key using a Set node named set API key. Replace the placeholder with your actual key.

Navigation: Click the Set node → edit the value field for perplexityAPI.

This key authenticates your requests to Perplexity’s API.

Common Mistake: Forgetting to save your API key here will cause authorization errors in the next step.

4. Fetch News Using Perplexity AI HTTP Request

The Perplexity HTTP Request node calls the AI API endpoint with a JSON body containing parameters like model type, temperature, and a system prompt explaining the output format.

HTTP Details:

Method: POST
URL: https://api.perplexity.ai/chat/completions
Headers: Authorization: Bearer 
Body (JSON):
{
  "model": "llama-3.1-sonar-small-128k-online",
  "messages": [
    {
      "role": "system",
      "content": "You are a social media assistant summarizing tech news for Twitter/X. ... "
    },
    {
      "role": "user",
      "content": "{{ $('searchQuery').item.json.searchInput }}"
    }
  ],
  "temperature": 0.3,
  "top_p": 0.9,
  "return_citations": true,
  "search_domain_filter": ["perplexity.ai"],
  "search_recency_filter": "day",
  "max_tokens": 80,
  "presence_penalty": 0,
  "frequency_penalty": 1
}

This setup instructs Perplexity to reply with a precise headline and link in under 200 characters, perfect for X posts.

You can view the response in the node’s execution preview after triggering a test run.

Common Mistake: Incorrect or expired API keys will return authentication errors. Double-check your token.

5. Post the AI-Generated Summary to X

Finally, the Post to X Twitter node posts the content from the API response on your linked X account.

Navigation: Click the Twitter node → set text to =$json.choices[0].message.content, which extracts the concise message generated earlier.

This step requires prior OAuth2 setup with your X app credentials.

Common Mistake: Improper credential linkage will cause posting failure. Verify credentials in the node settings.

Customizations ✏️

  • Change the news topic: Modify the searchInput value in the searchQuery Set node to focus on any other technology or subject.
  • Adjust posting frequency: In the Schedule Trigger node, change the hourly interval or switch to daily timings to better fit your audience’s engagement patterns.
  • Include images or media: Enhance the Twitter posts by expanding the HTTP Request node to retrieve media URLs and modify the Twitter node to post images.
  • Add more context to tweets: Modify the system prompt in the HTTP Request node to include additional summary points or links based on your preferences.

Troubleshooting 🔧

Problem: “401 Unauthorized” from Perplexity API

Cause: Invalid or missing API key.

Solution: Confirm your key is correctly entered in the set API key node and that it has not expired.

Problem: Twitter posts are not appearing

Cause: OAuth credentials not correctly configured or insufficient permissions.

Solution: Go to the X developer portal, regenerate the OAuth2 tokens with tweet posting permissions, then update your credential link inside the Post to X node.

Pre-Production Checklist ✅

  • Validate API keys for Perplexity and X are correct and active.
  • Test the HTTP Request node to ensure it returns the expected headline and link.
  • Perform dry runs using the manual trigger option to confirm tweet formatting and posting.
  • Verify Schedule Trigger timing matches your intended frequency.

Deployment Guide

To deploy the workflow, toggle the active state in n8n to enable automatic execution. Monitor your workflow runs periodically through the n8n execution logs dashboard. Adjust scheduling or prompt details as necessary based on engagement.

FAQs

  • Q: Can I use another AI instead of Perplexity?
    A: Yes, but you’d need to customize the HTTP request node and prompts to fit the API of the alternative AI.
  • Q: Does this workflow consume many API credits?
    A: Each execution makes a single API call to Perplexity. The cost depends on your Perplexity plan, so monitor usage accordingly.
  • Q: Is my data safe?
    A: Data privacy depends on both Perplexity’s and n8n’s security. Use encrypted credentials and trusted hosting for safety.

Conclusion

By following this guide, you have automated the creation and posting of the latest AI news headlines on your X account using n8n and Perplexity AI. This saves you hours weekly and keeps your audience engaged with accurate, timely updates.

Next steps could include expanding this workflow to cover multiple topics, adding image media posts, or integrating analytics to track engagement from your tweets. Keep automating, and watch your social media presence grow effortlessly!

Promoted by BULDRR AI

Related Workflows

Automate Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation in n8n

A complete beginner guide to building an AI-powered SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free