curl --request DELETE \
--url https://api.example.com/api/clients/:id{
"message": "<string>",
"error": "<string>"
}Permanently delete a client and all associated data
curl --request DELETE \
--url https://api.example.com/api/clients/:id{
"message": "<string>",
"error": "<string>"
}curl -X DELETE https://your-domain.com/api/clients/clx1a2b3c4d5e6f7g8h9i0j1k \
-H "Cookie: next-auth.session-token=..."
const response = await fetch('/api/clients/clx1a2b3c4d5e6f7g8h9i0j1k', {
method: 'DELETE'
});
const result = await response.json();
{
"message": "Client deleted successfully"
}
{
"error": "Client not found or unauthorized"
}
{
"error": "Unauthorized"
}
{
"error": "Failed to delete client"
}
const deleteClient = async (clientId) => {
const confirmed = confirm(
'Are you sure you want to delete this client? ' +
'This will permanently delete all reports and cannot be undone.'
);
if (!confirmed) return;
try {
const response = await fetch(`/api/clients/${clientId}`, {
method: 'DELETE'
});
if (response.ok) {
// Update UI to remove client
console.log('Client deleted successfully');
}
} catch (error) {
console.error('Failed to delete client:', error);
}
};
const deleteClientWithStatus = async (clientId) => {
const statusElement = document.getElementById('status');
statusElement.textContent = 'Deleting client...';
try {
const response = await fetch(`/api/clients/${clientId}`, {
method: 'DELETE'
});
if (response.ok) {
statusElement.textContent = 'Client deleted successfully';
// Redirect or update UI
window.location.href = '/dashboard/clients';
} else {
const error = await response.json();
statusElement.textContent = `Error: ${error.error}`;
}
} catch (error) {
statusElement.textContent = 'Failed to delete client';
}
};