Skip to main content
DELETE
/
products
/
{id}
Delete Product
curl --request DELETE \
  --url https://api.example.com/products/{id}
{
  "204": {},
  "400": {},
  "404": {},
  "500": {}
}

Overview

This endpoint permanently removes a product from the database. The operation cannot be undone. All associated data, including category relationships, will be removed due to cascade deletion rules.

Path Parameters

id
long
required
The unique identifier of the product to delete

Response

This endpoint returns no content on successful deletion.

Status Codes

204
No Content
Product deleted successfully. No response body is returned.
404
Not Found
Product with the specified ID does not exist
400
Bad Request
Invalid product ID format (must be a valid long integer)
500
Internal Server Error
Server error occurred while deleting the product

Examples

curl -X DELETE "http://localhost:8080/products/1" \
  -H "Accept: application/json"

Success Response (204 No Content)

Status: 204 No Content Body: (empty) Headers:
Content-Length: 0
Date: Tue, 03 Mar 2026 15:45:30 GMT

Error Response Example (404 Not Found)

Status: 404 Not Found
{
  "timestamp": "2026-03-03T15:45:30",
  "status": 404,
  "error": "Not Found",
  "message": "Could not find product 999",
  "path": "/products/999"
}

Error Response Example (400 Bad Request)

Status: 400 Bad Request
{
  "timestamp": "2026-03-03T15:45:30",
  "status": 400,
  "error": "Bad Request",
  "message": "Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'",
  "path": "/products/invalid"
}

Verification

After deletion, you can verify the product no longer exists:
curl -X GET "http://localhost:8080/products/1" \
  -H "Accept: application/json"
# Should return 404 Not Found
Permanent Deletion: This operation permanently deletes the product from the database and cannot be undone. Make sure you want to delete the product before calling this endpoint.
Cascade Effects: Due to the @OneToMany relationship with cascade = CascadeType.ALL and orphanRemoval = true on the categories field, all ProductCategory associations will be automatically deleted when the product is deleted.
Idempotency: This endpoint is not idempotent. Attempting to delete the same product twice will result in a 404 Not Found error on the second attempt.
Best Practice: Consider implementing soft deletes (marking products as inactive rather than physically deleting them) if you need to maintain historical records or support undo functionality.

Build docs developers (and LLMs) love