Skip to content

Delete Firewall Rule

Permanently deletes a firewall rule. This action cannot be undone.

DELETE /v1/firewall-rules/{id}
ParameterTypeRequiredDescription
idintegerYesThe firewall rule ID
import Tokenrouter from 'tokenrouter';
const client = new Tokenrouter({
apiKey: process.env.TOKENROUTER_API_KEY
});
await client.firewallRules.delete(123);
console.log('Rule deleted successfully');
{
"success": true
}
{
"error": {
"message": "Firewall rules are not available on the free plan",
"type": "authorization_error",
"http_status": 403
}
}
{
"error": {
"message": "Firewall rule not found",
"type": "not_found_error",
"http_status": 404
}
}

Always verify before deleting:

// Get rule details first
const rule = await client.firewallRules.retrieve(ruleId);
console.log(`About to delete: ${rule.data.name}`);
console.log(`Priority: ${rule.data.priority}`);
console.log(`Action: ${rule.data.action}`);
console.log(`Pattern: ${rule.data.pattern}`);
// Confirm deletion
const confirmed = confirm('Delete this rule?');
if (confirmed) {
await client.firewallRules.delete(ruleId);
console.log('Rule deleted');
}

Delete multiple rules:

// Delete all disabled rules
const rules = await client.firewallRules.list();
const disabledRules = rules.data.filter(r => !r.is_enabled);
console.log(`Found ${disabledRules.length} disabled rules to delete`);
for (const rule of disabledRules) {
await client.firewallRules.delete(rule.id);
console.log(`Deleted: ${rule.name}`);
}

Save rule configuration before deleting:

import fs from 'fs';
// Backup rule before deleting
const rule = await client.firewallRules.retrieve(ruleId);
const backup = {
name: rule.data.name,
priority: rule.data.priority,
is_enabled: rule.data.is_enabled,
scope: rule.data.scope,
type: rule.data.type,
pattern: rule.data.pattern,
action: rule.data.action,
replacement: rule.data.replacement,
deleted_at: new Date().toISOString()
};
// Save backup to file
fs.appendFileSync(
'firewall-deletions.json',
JSON.stringify(backup) + '\n'
);
// Delete
await client.firewallRules.delete(ruleId);
console.log('Rule deleted and backed up');

Consider disabling rules instead of deleting:

// Instead of deleting, disable the rule
await client.firewallRules.update(ruleId, {
is_enabled: false
});
// Can be re-enabled later if needed
await client.firewallRules.update(ruleId, {
is_enabled: true
});
ScenarioRecommendation
Testing a ruleDisable it
Seasonal pattern (e.g., holiday-specific)Disable it
Temporary relaxation of rulesDisable it
Deprecated pattern no longer neededDelete it
Duplicate ruleDelete it
Incorrect rule that never workedDelete it
Rule with security vulnerabilitiesDelete it
const rules = await client.firewallRules.list();
const now = new Date();
const ninetyDaysAgo = new Date(now.getTime() - 90 * 24 * 60 * 60 * 1000);
for (const rule of rules.data) {
const updated = new Date(rule.updated_at);
if (!rule.is_enabled && updated < ninetyDaysAgo) {
console.log(`Deleting old rule: ${rule.name} (last updated ${updated.toLocaleDateString()})`);
await client.firewallRules.delete(rule.id);
}
}
// Delete all warn-action rules (if moving to logging)
const rules = await client.firewallRules.list();
const warnRules = rules.data.filter(r => r.action === 'warn');
console.log(`Removing ${warnRules.length} warn-only rules`);
for (const rule of warnRules) {
await client.firewallRules.delete(rule.id);
}
  1. Always get rule details before deleting
  2. Backup critical rules before deletion
  3. Prefer disabling over deleting when unsure
  4. Delete in batches carefully to avoid accidents
  5. Document deletion reasons in change log
  6. Test after deletion to ensure no unexpected behavior
  7. Review dependencies - check if other systems reference the rule

If you accidentally deleted a rule and have a backup:

// Recreate from backup
const backup = {
name: "Block Credit Cards",
priority: 100,
is_enabled: true,
scope: "prompt",
type: "regex",
pattern: "\\d{16}",
action: "block",
replacement: null
};
const restored = await client.firewallRules.create(backup);
console.log(`Restored rule: ${restored.data.id}`);