/bulk-delete-webflow-301.js Secret
Last active
August 4, 2023 13:41
Star
You must be signed in to star a gist
Bulk Delete 301 Redirects From Webflow
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
const deleteRedirects = async (redirects) => { | |
const xsrfToken = document | |
.querySelector('meta[name="_csrf"]') | |
.getAttribute('content'); | |
const shortName = window.location.href.split('/')[5]; | |
for (const path of redirects) { | |
const bodyContent = JSON.stringify({ path }); | |
try { | |
await fetch( | |
`https://webflow.com/api/sites/${shortName}/redirect/delete`, | |
{ | |
headers: { | |
'content-type': 'application/json', | |
'x-xsrf-token': xsrfToken, | |
}, | |
body: bodyContent, | |
method: 'POST', | |
} | |
); | |
console.log(`Deleted redirect: ${path}`); | |
} catch (error) { | |
console.error(`Error deleting redirect: ${path}, ${error}`); | |
} | |
} | |
}; | |
const redirectsToDelete = ['/first-slug', '/second-slug']; | |
deleteRedirects(redirectsToDelete); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment