Skip to main content

DELETE /api/products/:id

Permanently deletes a product from the system. This action cannot be undone.

Authentication

Required. Must include a valid JWT token in the Authorization header.

Authorization

Admin role required.

Request Headers

Authorization: Bearer <jwt_token>

Path Parameters

id
string
required
The unique identifier of the product to delete

Response

message
string
Success message confirming the deletion

Example Request

curl -X DELETE https://api.example.com/api/products/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example Response

{
  "message": "Product deleted successfully"
}

Error Responses

404 - Not Found

{
  "error": "Product not found"
}

401 - Unauthorized

{
  "error": "Authentication required"
}

403 - Forbidden

{
  "error": "Admin access required"
}

500 - Internal Server Error

{
  "error": "Database connection failed"
}

Notes

  • This endpoint performs a hard delete using findByIdAndDelete
  • Consider implementing soft deletes by setting isActive: false instead for better data retention
  • Any orders or references to this product may be affected by deletion

Build docs developers (and LLMs) love