Skip to main content

Endpoint

DELETE /api/especialidades/:id

Authentication

This endpoint requires authentication with an admin role. Include a valid JWT token in the Authorization header.
Authorization: Bearer <token>

Description

Permanently deletes a medical specialty from the system. This is a hard delete operation that removes the record from the database.
This is a permanent deletion. The specialty cannot be recovered after deletion. Make sure no doctors are assigned to this specialty before attempting to delete it.

Path Parameters

id
integer
required
Unique identifier of the specialty to delete

Response

Returns a success message confirming the deletion.

Response Fields

message
string
Confirmation message indicating successful deletion

Example Request

curl -X DELETE "https://api.example.com/api/especialidades/4" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "message": "Especialidad eliminada correctamente"
}

Error Responses

401 Unauthorized
Missing or invalid authentication token
{
  "message": "Token no proporcionado"
}
403 Forbidden
User does not have admin role
{
  "message": "Acceso denegado"
}
404 Not Found
Specialty with the specified ID does not exist
{
  "message": "Especialidad no encontrada"
}
409 Conflict
Cannot delete specialty because doctors are assigned to it
{
  "message": "No se puede eliminar: hay médicos asignados"
}
500 Internal Server Error
Server error while deleting specialty
{
  "message": "Error al eliminar especialidad"
}

Foreign Key Constraint

Cannot delete specialty with assigned doctorsIf any doctors are currently assigned to this specialty, the deletion will fail with a 409 Conflict error. You must either:
  • Reassign all doctors to different specialties using the Update Doctor endpoint
  • Deactivate the doctors using the Delete Doctor endpoint
This constraint ensures data integrity and prevents orphaned doctor records.

Best Practices

Before deleting a specialty:
  1. Check if any doctors are assigned to it
  2. Reassign those doctors to other specialties if needed
  3. Consider the impact on historical appointment data
  4. Document the reason for removing the specialty

Build docs developers (and LLMs) love