Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created August 4, 2023 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/bf34cc7da8e1235c500df63a0846d2ca to your computer and use it in GitHub Desktop.
Save nocodesupplyco/bf34cc7da8e1235c500df63a0846d2ca to your computer and use it in GitHub Desktop.
Download All Webflow Redirects as CSV
const getRedirects = async () => {
const xsrfToken = document
.querySelector('meta[name="_csrf"]')
.getAttribute('content');
const shortName = window.location.href.split('/')[5];
try {
const response = await fetch(`https://webflow.com/api/sites/${shortName}`, {
headers: {
'content-type': 'application/json',
'x-xsrf-token': xsrfToken,
},
});
const data = await response.json();
const csv = data.siteMeta.redirects.reduce(
(acc, { src, target }) => (acc += `"${src}","${target}"\n`),
'src,target\n'
);
const csvBlob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(csvBlob);
const link = document.createElement('a');
link.href = url;
link.download = 'redirects.csv';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
console.error(error);
}
};
getRedirects();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment