The code
download-x-video.mjs
x.com and twitter.com post links both work, with or without tracking parameters.
What comes back
The finished job fromGET /import/status:
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
webhookUrland 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: trueto 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.