Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Last active August 4, 2023 13:41
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/6b8477578e2c9971e009ac3ed388780d to your computer and use it in GitHub Desktop.
Save nocodesupplyco/6b8477578e2c9971e009ac3ed388780d to your computer and use it in GitHub Desktop.
Bulk Delete 301 Redirects From Webflow
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