Auto-Post YouTube Videos to X with n8n
Save time and guarantee every new YouTube upload gets the attention it deserves by automating social promotion with n8n. In this guide you’ll learn how to use a simple n8n workflow to detect new videos, generate an engaging post using OpenAI, publish it to X (Twitter) and send a Slack notification — all automatically.
Why automate YouTube → X posting?
Manual sharing is repetitive and prone to delay. Automation helps you:
- Post immediately when a video goes live
- Keep messaging consistent using AI-powered copy
- Save time so you can focus on creating
- Notify your team via Slack when a video is published
Overview of the workflow
The workflow in this tutorial follows five steps (matching the visual template):
- Schedule Trigger — check for new videos on a schedule (example: every 30 minutes)
- Fetch YouTube Videos — call the YouTube API to get recent uploads from your channel
- Generate Social Post — use OpenAI to create a short post that links to the video
- Publish to X — post the generated message to X using OAuth2 credentials
- Slack Notification — send a message to a Slack channel letting your team know
Required credentials and services
- YouTube OAuth2 account (to call the YouTube Data API)
- X (Twitter) OAuth2 credentials for create/tweet access
- OpenAI API key (for generating the social copy)
- Slack token with permissions to post to your chosen channel
- n8n instance (cloud or self-hosted) with those credentials configured
Step-by-step setup
1. Schedule Trigger
Add a Schedule Trigger node and set an interval. The template uses every 30 minutes — choose a cadence that fits your channel size and API rate limits.
2. Fetch YouTube Videos
Use the YouTube node and configure these key fields:
- Resource: video
- Limit: 1 (or more if you want a batch)
- Channel ID: your YouTube channel ID (find it at youtube.com/account_advanced or in YouTube Studio → Settings → Channel)
- Published After: dynamic value so you only get recently published videos (example used in the template: now – 30 minutes)
Important: set the Channel ID correctly. The sticky note in the template reminds you to insert your channel ID. If you miss this, the node won’t return your uploads.
3. Generate Social Post (OpenAI)
Add a LangChain/OpenAI node (or HTTP request node to call the OpenAI API). The template prompt looks like this:
=Write an engaging post about my latest YouTube video for X (Twitter) of no more than 140 characters in length. Link to the video at https://youtu.be/{{ $json.id.videoId }} use this title and description: {{ $json.snippet.title }} {{ $json.snippet.description }}
Tips for prompts:
- Keep the instruction explicit: maximum length, include the link, include hashtags or not
- Consider adding tone, target audience, or one-line hook guidance
- Keep an eye on output length — you can add a follow-up n8n function to truncate safely to X’s character limit
4. Publish to X
Use the X/Twitter node with OAuth2 credentials to post the generated message. Map the node’s text field to the OpenAI node output (for example: {{ $json.message.content }} in the node parameters).
Note: X’s API and policies change from time to time. Make sure your developer access and scopes include create/tweet privileges and follow the platform’s rate limits.
5. Slack Notification
Finally, send a short internal notification to Slack so your team knows which video went live. The template uses a simple text like:
New YouTube video posted: {{ $json.snippet.title }} https://youtu.be/{{ $json.id.videoId }}
Enhancements and best practices
Prevent duplicate posts
When querying YouTube on a schedule, you can accidentally post the same video more than once. Options to avoid duplicates:
- Persist the last posted video ID in a database or file (Google Sheets, Airtable, or n8n’s own credentials or external DB)
- Use a Set or If node to compare the latest video ID to the stored value before continuing
- Mark the video as posted by writing back to a data store after publishing
Rate limits and quotas
Watch YouTube API quotas (calls per day) and X API rate limits. Batch checks or increase the schedule interval if you run into limits.
Message formatting and hashtags
Decide on a consistent style for posts: one-line hook, 1–2 hashtags, and the youtu.be link. You can include the video title and call-to-action like “Watch now” or “New video — link in bio” depending on your audience.
Testing and safety
- Test the workflow with a private video or a sandbox account first
- Use an approval step if you prefer human review before posting (add a Slack message with action buttons or a manual webhook trigger)
- Log failures and retries with n8n’s error workflow or a dedicated Slack alert
Sample prompt variations
Short hook (140 chars):
New video: {{ $json.snippet.title }} — watch now: https://youtu.be/{{ $json.id.videoId }} #YouTube #NewVideo
Conversational tone:
Just dropped a new video: "{{ $json.snippet.title }}" — quick tips and demo inside. Watch now: https://youtu.be/{{ $json.id.videoId }}
Troubleshooting checklist
- If the YouTube node returns no items, confirm Channel ID and publishedAfter settings.
- If OpenAI returns long text, add a truncate step or enforce a max tokens/length in your prompt.
- If publishing to X fails, check OAuth scopes, API keys, and rate limits.
- If Slack notifications don’t arrive, verify the Slack token and channel name.
Security and compliance
Keep API keys and OAuth tokens secure — store them as n8n credentials and do not hardcode secrets in nodes. Respect platform policies when automating posting to social networks and ensure you have permissions to republish content.
Wrapping up
This n8n automation template gives you a reliable way to promote every new YouTube upload to X and notify your team on Slack — with the added boost of AI-generated copy. Customize prompts, tweak the schedule, and add deduplication or approval steps to match your workflow.
Ready to try it? Import the workflow template into n8n, add your Channel ID and credentials, and enable the workflow. Monitor the first few runs to confirm behavior and tweak your OpenAI prompt for the perfect voice.
Call to action
Want a copy of this template or help customizing it for your channel? Contact us or subscribe to our newsletter for more automation templates and tutorials. Start automating your social promotion today and spend more time creating great content.
Template reference: Schedule Trigger → Fetch YouTube Videos → Generate Social Post (OpenAI) → Publish to X → Slack Notification.
