Facebook gives a product no simple way to turn a reel or video link into a file. This tutorial shows how to take whatever a user pastes, including an fb.watch short link, and get the video’s details and direct MP4 links with one call.
Before you start
Create a free key in the dashboard and keep it in an environment variable called IGRAMAPI_KEY. The free plan has 100 credits a month, and every Facebook endpoint works on it. A reel or video lookup costs 1 credit.
Step 1: look up a reel
Pass the reel’s link, or a short link copied from the app:
curl "https://api.igramapi.com/v1/facebook/reels?url=https://www.facebook.com/reel/1234567890123456" \
-H "Authorization: Bearer $IGRAMAPI_KEY"
The parts of the response you will use most:
{
"id": "1234567890123456",
"caption": "Behind the scenes at the studio today",
"created_at": 1761900000,
"video": {
"hd_url": "https://video.xx.fbcdn.net/v/example/clip-hd.mp4",
"sd_url": "https://video.xx.fbcdn.net/v/example/clip-sd.mp4",
"width": 1080,
"height": 1920,
"duration": 23.125,
"thumbnail_url": "https://scontent.xx.fbcdn.net/v/example/thumb.jpg"
},
"author": { "name": "Example Studio", "is_verified": true },
"stats": { "likes": 2767, "comments": 106, "shares": 16, "views_str": "18K" },
"cached": false
}
The response also has a dash_manifest string inside video (12 to 15 KB of XML) and a soundtrack object. views_str is the view count as Facebook shows it, so it is text such as 18K.
Step 2: Python, with a download
import os
import requests
API = "https://api.igramapi.com"
HEADERS = {"Authorization": f"Bearer {os.environ['IGRAMAPI_KEY']}"}
def facebook_reel(url):
response = requests.get(f"{API}/v1/facebook/reels", params={"url": url}, headers=HEADERS, timeout=30)
if not response.ok:
raise RuntimeError(response.json()["error"]["message"])
return response.json()
def save(link, path):
with requests.get(link, stream=True, timeout=60) as file:
file.raise_for_status()
with open(path, "wb") as out:
for chunk in file.iter_content(1 << 20):
out.write(chunk)
reel = facebook_reel("https://fb.watch/abc123/")
link = reel["video"]["hd_url"] or reel["video"]["sd_url"]
save(link, f"{reel['id']}.mp4")
print(reel["author"]["name"], reel["stats"]["views_str"])
Prefer HD when it is there, and fall back to SD, because either can be null when Facebook publishes a single quality.
Step 3: the same in Node.js
import { writeFile } from "node:fs/promises";
const API = "https://api.igramapi.com";
async function facebookReel(url) {
const response = await fetch(`${API}/v1/facebook/reels?url=${encodeURIComponent(url)}`, {
headers: { Authorization: `Bearer ${process.env.IGRAMAPI_KEY}` },
});
if (!response.ok) throw new Error((await response.json()).error.message);
return response.json();
}
const reel = await facebookReel("https://www.facebook.com/reel/1234567890123456");
const link = reel.video.hd_url ?? reel.video.sd_url;
const file = await fetch(link);
await writeFile(`${reel.id}.mp4`, Buffer.from(await file.arrayBuffer()));
console.log(reel.author.name, reel.stats.views_str);
Things to know
- The links are temporary.
hd_url,sd_urlandthumbnail_urlare Facebook CDN links with an expiry. Download the file soon after the call, and call the endpoint again for a fresh link instead of storing an old one. - Short links work. fb.watch links and facebook.com/share/ links are followed to the reel or video. For a Watch or page video, call
/v1/facebook/videoswith the same kind of link. - Only public videos, and only from a link. Private and deleted videos return HTTP 404, and there is no lookup by page or username.
- Rights. Only save content you have the right to use, show where it came from and remove it on request. See the acceptable use policy.
Handling errors
| Status | Code | What to do |
|---|---|---|
| 400 | invalid_target |
The input is not a Facebook video or reel link or id. Ask the user for another link. |
| 404 | reel_not_found / video_not_found |
The video was deleted, is private, or is not public. Do not retry. |
| 429 | rate_limit_exceeded |
Wait for Retry-After seconds. |
| 502 | upstream_error |
Facebook could not be reached. Retry shortly; this is refunded. |
See error handling for retry advice, and credits and rate limits for what each call costs.