Copy and paste this on your list page after you log in.
Last active
November 6, 2024 16:07
-
-
Save ColeTownsend/087b184d02f4753c9d059b6dc2d28963 to your computer and use it in GitHub Desktop.
Export Cloudflare Bulk Redirect List to CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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