Skip to content

Instantly share code, notes, and snippets.

@ColeTownsend
Last active November 6, 2024 16:07
Show Gist options
  • Save ColeTownsend/087b184d02f4753c9d059b6dc2d28963 to your computer and use it in GitHub Desktop.
Save ColeTownsend/087b184d02f4753c9d059b6dc2d28963 to your computer and use it in GitHub Desktop.
Export Cloudflare Bulk Redirect List to CSV

Copy and paste this on your list page after you log in.

(async () => {
const [_, accountId, listId] = window.location.href.match(/\/([a-f0-9]{32})\/bulk-redirects\/redirect-list\/([a-f0-9]{32})/) || [];
if (!accountId || !listId) return console.error("Invalid URL structure");
const response = await fetch(`https://dash.cloudflare.com/api/v4/accounts/${accountId}/rules/lists/${listId}/items?per_page=500`, {
headers: { "accept": "*/*", "credentials": "include" }
});
const redirectsList = (await response.json()).result.map(item => ({
from: item.redirect.source_url,
to: item.redirect.target_url
}));
const csvContent = "data:text/csv;charset=utf-8," + redirectsList.map(r => `${r.from},${r.to}`).join("\n");
Object.assign(document.createElement("a"), { href: encodeURI(csvContent), download: "redirects.csv" }).click();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment