Skip to main content
Your users paste an X post and your Node backend needs the video file. Without an X developer account there’s no stable way to get it from a server: page scraping and unofficial endpoints break, and requests from cloud IPs get blocked or rate-limited. This sends the post link to Importly and saves the finished MP4. It runs on Node 18 or later with no dependencies.

The code

download-x-video.mjs
Send the link as your users paste it: x.com and twitter.com post links both work, with or without tracking parameters.

What comes back

The finished job from GET /import/status:
X serves each video in several bitrates. You don’t pick one: Importly takes the best stream at or below videoQuality and gives you a single MP4. Set includeVideo: false for the audio only, or add includeTranscript: true for a timestamped transcript in the same job. All options are in Downloads.

Errors to handle

Importly fetches what’s public. Every error has a documentationUrl with the fix. See Media unavailable and Error handling. Only download videos your users have the right to use.

Check a post before you download

Users often paste posts that have only text or images, and those imports fail. POST /metadata/basic returns the title and duration for $0.003, so you can confirm there’s a video, and how long it is, before you start an import. See Metadata.

In production

  • Don’t make a web request wait on the loop above. Pass webhookUrl and save the file when Importly calls you back (Webhooks), and keep a status check as a fallback.
  • Copy the file somewhere permanent, or set store: true to have every import land in your own bucket (recipe).
  • For many links at once, see Batch imports.
Downloads cost $0.002 per MB, with a $0.01 minimum, so a one-minute clip at 720p is usually two to four cents. Try it free, no card required. See Pricing & credits.