async function toggleForwarding(enabled, email) {
try {
const response = await fetch("/api/email-forwarding/email-forwarding-toggle", {
method: "POST",
headers: {
"X-API-KEY": "YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({ enabled, email })
});
if (!response.ok) {
const errorData = await response.json();
console.error("Failed to toggle:", errorData.error);
return;
}
const data = await response.json();
console.log("Toggle result:", data);
} catch (err) {
console.error("Unexpected error:", err);
}
}
// Example usage:
// toggleForwarding(true, "[email protected]");