Documentation Index
Fetch the complete documentation index at: https://mintlify.com/zulfikarrosadi/juadah-backend/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Delete a product from the Juadah bakery catalog. This operation is permanent and will also remove all associated images from Cloudinary.
Endpoint
Authentication & Authorization
This endpoint requires Admin access. Regular users will receive a 403 Forbidden error.
Requires authentication via cookie-based session with admin role.
Path Parameters
The unique identifier of the product to delete.
Response
On successful deletion, this endpoint returns a 204 No Content status with no response body.
Example Request
Using cURL
curl -X DELETE "https://juadah-backend.vercel.app/api/products/1" \
-H "Cookie: accessToken=your-admin-access-token"
Using JavaScript (Fetch API)
const response = await fetch('https://juadah-backend.vercel.app/api/products/1', {
method: 'DELETE',
credentials: 'include' // Include cookies for authentication
});
if (response.status === 204) {
console.log('Product deleted successfully');
}
Using Python (requests)
import requests
url = "https://juadah-backend.vercel.app/api/products/1"
cookies = {
'accessToken': 'your-admin-access-token'
}
response = requests.delete(url, cookies=cookies)
if response.status_code == 204:
print("Product deleted successfully")
Using Axios (JavaScript)
import axios from 'axios';
try {
const response = await axios.delete(
'https://juadah-backend.vercel.app/api/products/1',
{
withCredentials: true // Include cookies
}
);
if (response.status === 204) {
console.log('Product deleted successfully');
}
} catch (error) {
console.error('Error deleting product:', error.response.data);
}
Example Response
Success Response (204)
No content is returned. The HTTP status code 204 indicates successful deletion.
Forbidden Error (403)
Returned when a non-admin user attempts to delete a product.
{
"status": "fail",
"errors": {
"code": 403,
"message": "this action is only for user with admin access"
}
}
Not Found Error (404)
Returned when the product with the specified ID doesn’t exist.
{
"status": "fail",
"errors": {
"code": 404,
"message": "resource you're looking for is not found"
}
}
Error Handling
When handling this endpoint, check for the following status codes:
204: Product successfully deleted
403: User lacks admin privileges
404: Product not found
JavaScript Error Handling Example
try {
const response = await fetch(
`https://juadah-backend.vercel.app/api/products/${productId}`,
{
method: 'DELETE',
credentials: 'include'
}
);
if (response.status === 204) {
// Success - product deleted
return { success: true };
}
const error = await response.json();
if (response.status === 403) {
// User is not an admin
throw new Error('Admin access required');
}
if (response.status === 404) {
// Product doesn't exist
throw new Error('Product not found');
}
throw new Error(error.errors.message);
} catch (error) {
console.error('Failed to delete product:', error);
return { success: false, error: error.message };
}
Important Notes
This operation is permanent and cannot be undone. All product data and associated images will be permanently deleted.
- Deletion removes the product from the database
- All associated images are deleted from Cloudinary
- This operation cannot be reversed
- Only users with admin role can delete products
- Returns
204 No Content on success (no response body)
Implementation Details
- The endpoint is protected by the
adminAccess middleware (routes.ts:71)
- Product deletion is handled by
ProductHandler.deleteProductById (handler.ts:87-93)
- Associated images on Cloudinary are also removed during deletion
- The operation returns HTTP 204 with no content on success
- Failed deletions return HTTP 404 with error details