Before I touch a client's Webflow CMS in bulk, whether that's a CSV import, a migration, or a find-and-replace across 300 blog posts, I take a copy of every collection as JSON. It takes one script and about a minute, and it has saved me more than once when a "small" import overwrote the wrong field.
Webflow does let you export a collection to CSV from the CMS. That's fine for one collection. But when a site has eight collections and you want everything in one go, with item IDs, draft and archived flags, and timestamps, the Data API is quicker.
Here's the script I use.
What you need
- Node 18 or newer (for built-in
fetch). - A Webflow API token with CMS read access (
cms:read). A site token from your site settings works. - The site ID. If your token can read sites,
GET https://api.webflow.com/v2/siteslists them with their IDs.
The script
// backup-webflow-cms.mjs
// Node 18+. Usage: WEBFLOW_TOKEN=... WEBFLOW_SITE_ID=... node backup-webflow-cms.mjs
import { writeFile, mkdir } from "node:fs/promises";
const TOKEN = process.env.WEBFLOW_TOKEN;
const SITE_ID = process.env.WEBFLOW_SITE_ID;
const API = "https://api.webflow.com/v2";
if (!TOKEN || !SITE_ID) {
console.error("Set WEBFLOW_TOKEN and WEBFLOW_SITE_ID first.");
process.exit(1);
}
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
async function get(path) {
for (let attempt = 0; attempt < 5; attempt++) {
const res = await fetch(API + path, {
headers: { Authorization: `Bearer ${TOKEN}`, accept: "application/json" },
});
if (res.status === 429) {
const wait = Number(res.headers.get("retry-after")) || 60;
console.log(`Rate limited, waiting ${wait}s`);
await sleep(wait * 1000);
continue;
}
if (!res.ok) throw new Error(`${res.status} on ${path}: ${await res.text()}`);
return res.json();
}
throw new Error(`Gave up on ${path} after 5 tries`);
}
async function allItems(collectionId) {
const items = [];
let offset = 0;
while (true) {
const page = await get(`/collections/${collectionId}/items?limit=100&offset=${offset}`);
items.push(...page.items);
offset += page.items.length;
const total = page.pagination?.total;
if (page.items.length < 100) break;
if (total !== undefined && offset >= total) break;
}
return items;
}
const stamp = new Date().toISOString().slice(0, 10);
const dir = `webflow-backup-${stamp}`;
await mkdir(dir, { recursive: true });
const { collections } = await get(`/sites/${SITE_ID}/collections`);
for (const c of collections) {
const items = await allItems(c.id);
await writeFile(`${dir}/${c.slug}.json`, JSON.stringify({ collection: c, items }, null, 2));
const drafts = items.filter((i) => i.isDraft).length;
const archived = items.filter((i) => i.isArchived).length;
console.log(`${c.displayName}: ${items.length} items (${drafts} draft, ${archived} archived)`);
}
console.log(`Saved to ./${dir}`);
Run it:
WEBFLOW_TOKEN=xxx WEBFLOW_SITE_ID=yyy node backup-webflow-cms.mjs
You get a dated folder with one file per collection, plus a line per collection in the terminal:
Blog Posts: 214 items (6 draft, 3 archived)
Authors: 9 items (0 draft, 0 archived)
(Example output, your numbers will differ.)
Why it's built this way
It uses /items, not /items/live. The live endpoint only returns published items. For a backup you want the drafts and archived items too, since those are exactly the ones nobody remembers exist until they're gone. Each item carries isDraft and isArchived, so you can still tell them apart.
Paging is offset based, 100 at a time. That's the API's maximum limit. The loop stops when a page comes back short or the offset reaches pagination.total.
It waits on 429s instead of crashing. Webflow's limit is per token: 60 requests a minute on Starter and Basic plans, 120 on CMS, eCommerce and Business. A site with a couple of thousand items can hit that. When it does, the API sends a Retry-After header and the script sleeps for that long.
The whole item is saved, not just fieldData. IDs, createdOn, lastUpdated and lastPublished are what you'll want when you're comparing before and after.
How I actually use the files
Most of the time it's a diff. Take a backup, do the import, take another, and compare the two folders. If an import was supposed to touch 40 posts and the diff shows 214 changed, you know before the client does.
A few things to keep in mind:
- This is a read-only backup, not a restore tool. Putting data back means writing it through the API again, and that's a separate script you'll want to test on a duplicate site first.
- Look at your own reference and multi-reference fields in the output before relying on them for anything. Check what they contain rather than assuming.
- Images aren't downloaded. The JSON holds whatever image data the API returns for each field, not the files.
- Keep the token out of the repo. An env var or a
.envfile that's in.gitignoreis enough.
If you're setting up a CMS for a team that will be editing it every week, I wrote about the structure I use (collections, fields and the rules that stop it getting messy) here: https://rizehub.ph/blog/webflow-cms-setup-for-marketing-teams
Top comments (0)