Skip to main content

Delete Service Record

Permanently delete a lubrication service record.
DELETE /api/engrases/:id

Path Parameters

id
number
required
Service record ID to delete

Response

Returns a success message upon deletion.
message
string
Confirmation message

Example Request

curl -X DELETE "https://api.example.com/api/engrases/102" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Example Response

{
  "message": "Engrase eliminado exitosamente"
}

Important Notes

This operation is permanent and cannot be undone. The service record will be completely removed from the database.
Before deleting, consider if you should:
  • Archive the record instead of deleting it
  • Export the data for backup purposes
  • Verify with the user that deletion is intended

Authorization

Only authenticated users with appropriate permissions can delete service records.

Error Responses

Service Not Found

When the specified ID doesn’t exist:
{
  "error": "Engrase not found"
}
Status: 404

Unauthorized

When the token is missing or invalid:
{
  "error": "Unauthorized"
}
Status: 401

Database Error

If there’s a database constraint violation:
{
  "error": "Cannot delete: record has dependencies"
}
Status: 400

Best Practices

Confirm Before Delete: Always show a confirmation dialog in your UI
Soft Delete Alternative: Consider implementing a “deleted” flag instead of hard deletion
Audit Log: Keep a log of deletions for accountability
Permission Check: Verify user has delete permissions before allowing this action

Example Implementation

JavaScript with Confirmation

async function deleteService(serviceId) {
  // Confirm with user
  const confirmed = confirm('¿Está seguro de eliminar este registro?');
  if (!confirmed) return;
  
  try {
    const response = await fetch(`https://api.example.com/api/engrases/${serviceId}`, {
      method: 'DELETE',
      headers: {
        'Authorization': `Bearer ${accessToken}`
      }
    });
    
    if (!response.ok) {
      throw new Error('Delete failed');
    }
    
    const data = await response.json();
    console.log(data.message);
    // Refresh the service list
  } catch (error) {
    console.error('Error deleting service:', error);
  }
}

Alternative to Deletion

Instead of deleting, consider marking records as inactive:
PUT /api/engrases/:id
{
  "activo": false,
  "observaciones": "Registro anulado - motivo: duplicado"
}
This approach preserves data for auditing while removing it from active queries.

Build docs developers (and LLMs) love