Post an RSS feed to social media with Ampost
By ArturPublished Updated
Watch a feed, and for each new item send one request to Ampost's REST API: it publishes the item's title and link on every network you name. Pick the n8n workflow or the Python script below. Both post each item once, even when a run is repeated.
What you'll build
- An automation that posts each new RSS or Atom item, its title and link, to several social networks at once.
- Either an n8n workflow with the RSS Feed Trigger, or a Python script for cron or a scheduled GitHub Actions job.
Before you start
- An Ampost account. The Free plan includes the REST API (2 social accounts and 15 posts every 30 days); scheduling needs the Pro plan or higher, and X the Max and Scale plans. See pricing.
- An API key from Settings, API keys. The key is shown once, so copy it when you create it. Treat it like a password.
- At least one connected social account, under Settings, Connections in the dashboard.
- The URL of your RSS or Atom feed, and n8n or Python 3.8 or later.
Download
Free to use and change. The file is shown in full below, so you can read it before you run it.
{
"name": "RSS feed to social media with Ampost",
"nodes": [
{
"parameters": {
"pollTimes": {
"item": [
{
"mode": "everyHour"
}
]
},
"feedUrl": "https://example.com/feed.xml"
},
"id": "7c2e1f40-3a9b-4d6e-8f10-2a3b4c5d6e01",
"name": "New feed item",
"type": "n8n-nodes-base.rssFeedReadTrigger",
"typeVersion": 1,
"position": [0, 0]
},
{
"parameters": {
"method": "POST",
"url": "https://api.ampost.io/api/posts",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "Idempotency-Key",
"value": "=rss-{{ ($json.guid || $json.link).hash('sha256').slice(0, 40) }}"
}
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify(Object.assign({ targets: [{ platforms: ['bluesky', 'threads'] }], text: $json.title, publishNow: true }, /^https?:\\/\\//.test($json.link || '') ? { linkUrl: $json.link } : {})) }}",
"options": {}
},
"id": "7c2e1f40-3a9b-4d6e-8f10-2a3b4c5d6e02",
"name": "Ampost: create post",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [240, 0],
"retryOnFail": true,
"maxTries": 3,
"waitBetweenTries": 5000,
"credentials": {
"httpHeaderAuth": {
"id": "ampostApiKey",
"name": "Ampost API key"
}
}
}
],
"connections": {
"New feed item": {
"main": [[{ "node": "Ampost: create post", "type": "main", "index": 0 }]]
}
},
"settings": {
"executionOrder": "v1"
},
"pinData": {},
"meta": {
"templateCredsSetupCompleted": false
}
}
#!/usr/bin/env python3
"""Post new RSS or Atom feed items to social media with the Ampost API.
Run it from cron (or a scheduled GitHub Actions job). Each run reads the feed,
posts every item it has not seen before, and remembers the items in a small
JSON state file. The first run only records the current items, so an existing
feed doesn't flood your accounts; pass --post-existing to post them too.
Python 3.8+, standard library only.
export AMPOST_API_KEY=amp_live_...
python rss_to_social.py --feed https://example.com/feed.xml --platforms bluesky,threads
# crontab: every 30 minutes
*/30 * * * * cd /opt/rss && AMPOST_API_KEY=amp_live_... python3 rss_to_social.py \
--feed https://example.com/feed.xml --platforms bluesky,threads
Guide: https://ampost.io/how-to/rss-feed-to-social-media
"""
import argparse
import hashlib
import json
import os
import sys
import urllib.error
import urllib.request
import xml.etree.ElementTree as ElementTree
API_URL = os.environ.get("AMPOST_API_URL", "https://api.ampost.io").rstrip("/")
ATOM = "{http://www.w3.org/2005/Atom}"
# Items read per run, newest first. Older items beyond this are never posted.
MAX_ITEMS = 20
# Seen item ids kept in the state file.
MAX_SEEN = 500
def fetch(url):
request = urllib.request.Request(url, headers={"User-Agent": "ampost-rss-template/1.0"})
with urllib.request.urlopen(request, timeout=30) as response:
return response.read()
def parse_feed(xml_bytes):
"""Return [{id, title, link}] for an RSS 2.0 or Atom feed, in feed order (newest first)."""
root = ElementTree.fromstring(xml_bytes)
items = []
for item in root.iter("item"): # RSS 2.0
link = (item.findtext("link") or "").strip()
guid = (item.findtext("guid") or "").strip()
items.append({"id": guid or link, "title": (item.findtext("title") or "").strip(), "link": link})
for entry in root.iter(ATOM + "entry"): # Atom
link = ""
for element in entry.findall(ATOM + "link"):
if element.get("rel", "alternate") == "alternate":
link = element.get("href", "")
break
entry_id = (entry.findtext(ATOM + "id") or "").strip()
items.append({"id": entry_id or link, "title": (entry.findtext(ATOM + "title") or "").strip(), "link": link})
return [item for item in items if item["id"]][:MAX_ITEMS]
def item_key(feed_url, item):
"""A stable Idempotency-Key per feed item: a re-run never posts the same item twice."""
return "rss-" + hashlib.sha256((feed_url + "\n" + item["id"]).encode("utf-8")).hexdigest()[:40]
def post_item(api_key, platforms, item, feed_url, template):
body = {
"targets": [{"platforms": platforms}],
"text": template.format(title=item["title"], link=item["link"]).strip(),
"publishNow": True,
}
if item["link"].startswith("https://") or item["link"].startswith("http://"):
body["linkUrl"] = item["link"]
request = urllib.request.Request(
API_URL + "/api/posts",
data=json.dumps(body).encode("utf-8"),
method="POST",
headers={
"Authorization": "Bearer " + api_key,
"Content-Type": "application/json",
"Idempotency-Key": item_key(feed_url, item),
"User-Agent": "ampost-rss-template/1.0",
},
)
with urllib.request.urlopen(request, timeout=60) as response:
return json.loads(response.read().decode("utf-8"))
def load_state(path):
try:
with open(path, encoding="utf-8") as handle:
return json.load(handle)
except FileNotFoundError:
return None
def save_state(path, seen):
temp = path + ".tmp"
with open(temp, "w", encoding="utf-8") as handle:
json.dump({"seen": seen[-MAX_SEEN:]}, handle, indent=2)
os.replace(temp, path)
def main(argv=None):
parser = argparse.ArgumentParser(description="Post new RSS/Atom items to social media with Ampost.")
parser.add_argument("--feed", required=True, help="the RSS or Atom feed URL")
parser.add_argument("--platforms", required=True, help="comma-separated, e.g. bluesky,threads,discord")
parser.add_argument("--template", default="{title}", help='post text; {title} and {link} are filled in (default "{title}")')
parser.add_argument("--state", default="rss_state.json", help="where seen items are remembered")
parser.add_argument("--post-existing", action="store_true", help="on the first run, post the items already in the feed")
args = parser.parse_args(argv)
api_key = os.environ.get("AMPOST_API_KEY")
if not api_key:
raise SystemExit("Set AMPOST_API_KEY to an API key from https://ampost.io/app/settings/api-keys")
platforms = [p.strip() for p in args.platforms.split(",") if p.strip()]
items = parse_feed(fetch(args.feed))
state = load_state(args.state)
if state is None and not args.post_existing:
save_state(args.state, [item["id"] for item in reversed(items)])
print("First run: remembered %d existing items, posted none." % len(items))
return 0
seen = list(state["seen"]) if state else []
failed = 0
for item in reversed(items): # oldest new item first
if item["id"] in seen:
continue
try:
post = post_item(api_key, platforms, item, args.feed, args.template)
except urllib.error.HTTPError as error:
payload = error.read().decode("utf-8", "replace")
if error.code == 409 and "IDEMPOTENCY_KEY_REUSED" in payload:
# Posted within the last 24 hours with other settings (template, platforms).
print("Already posted: %s" % item["title"])
else:
failed += 1
print("Not posted (%s): %s %s" % (error.code, item["title"], payload[:300]), file=sys.stderr)
if error.code == 429 or error.code >= 500:
continue # try again on the next run
# Other 4xx: Ampost refused the item (for example too long for a platform); don't retry it forever.
except urllib.error.URLError as error:
failed += 1
print("Could not reach %s: %s" % (API_URL, error.reason), file=sys.stderr)
continue # try again on the next run
else:
print("Posted %s (%s): %s" % (post["id"], post["status"], item["title"]))
seen.append(item["id"])
save_state(args.state, seen)
return 1 if failed else 0
if __name__ == "__main__":
sys.exit(main())
Steps
1. Choose n8n or Python
Use the n8n workflow if you already run n8n: it polls the feed for you. Use the Python script on any server with cron, or in a scheduled GitHub Actions job. Both send the same request.
Platform keys:
instagram(Instagram),facebook(Facebook),linkedin(LinkedIn),tiktok(TikTok),threads(Threads),twitter(X),discord(Discord),telegram(Telegram),bluesky(Bluesky),youtube(YouTube),pinterest(Pinterest).2. n8n: import the workflow and set the feed
Import
rss-to-social-media.n8n.json(three-dot menu, Import from File). Open RSS Feed Trigger and put your feed URL in Feed URL; it checks every hour. Add your API key to the HTTP Request node as a Header Auth credential: NameAuthorization, ValueBearer amp_live_...(as in the n8n guide).Change the networks in the body's
platforms, then activate the workflow. The trigger only reports items published after activation, so an old feed doesn't flood your accounts.3. Python: run the script from cron
Download
rss_to_social.py, setAMPOST_API_KEY, and run it once: the first run only remembers the items already in the feed (inrss_state.json) and posts none. After that, each run posts the new items, oldest first. Add--template "New post: {title}"to change the text.terminalexport AMPOST_API_KEY=amp_live_your_key_here python3 rss_to_social.py --feed https://example.com/feed.xml --platforms bluesky,threads # crontab -e: check every 30 minutes */30 * * * * cd /opt/rss && AMPOST_API_KEY=amp_live_your_key_here python3 rss_to_social.py --feed https://example.com/feed.xml --platforms bluesky,threads
Each item is posted once
Both send an Idempotency-Key made from the item's guid (or link): if the same item is sent again within 24 hours, Ampost returns the first post instead of a second one (or, if you changed the text or networks in between, answers 409 IDEMPOTENCY_KEY_REUSED, which the script reports as already posted). The script also keeps the ids it has seen, so it never resends an old item.
Each post is the item's title with its link attached as linkUrl, so networks that show link previews get a card. If Ampost refuses an item (for example a title too long for a network), the script prints the error and moves on; a rate limit or an outage leaves the item for the next run.
FAQ
Can I post the item's image too?
Yes. Add media: [{ url, type: 'image' }] to the request body with the item's image URL (for example from its enclosure or media:content). Ampost needs a public https URL.
Does it work with podcasts and YouTube channels?
Yes. A podcast feed and a YouTube channel's feed (youtube.com/feeds/videos.xml?channel_id=...) are RSS or Atom, so both templates read them. Building this into an app for many creators? See creator platforms.
Which social networks can I post to from an RSS feed?
Every network you connect to Ampost: Instagram, Facebook, LinkedIn, TikTok, Threads, X, Discord, Telegram, Bluesky, YouTube, Pinterest. Name them by key in targets[].platforms; X is twitter. LinkedIn and TikTok are coming soon.
Can I schedule a post instead of publishing it now?
Yes. Send scheduledFor with an ISO 8601 time (for example 2027-01-14T15:00:00Z) instead of publishNow: true, and Ampost publishes it then. Scheduling needs the Pro plan or higher.
What happens if the same request is sent twice?
The templates send an Idempotency-Key header. A retry with the same key within 24 hours returns the first post instead of creating a second one, so a retried step never posts twice.