Skip to main content

Delete Brand

This endpoint is used to delete an existing brand by its ID. Deleting a brand will automatically unassign it from all associated products.

Endpoint

  • URL: /brands/{id}
  • Method: DELETE

Replace {id} with the specific brand ID you want to delete.

Authentication

  • Header: accessToken
  • Type: Bearer Token
  • Value: <ACCESS-TOKEN>

Request Headers

HeaderTypeDescription
accessTokenstringAccess token for authentication. (required)

Path Parameters

ParameterTypeDescription
idstringThe unique identifier of the brand to be deleted.

Example Request

Here is an example using curl to delete a brand:

curl --location --request DELETE '<BASE-URL>/brands/brand_id_here' \
--header 'accessToken: <ACCESS-TOKEN>'

Note

  • Replace the placeholder in the URL with the actual brand ID.
  • Ensure you include a valid accessToken in the request to authenticate.

Response

  • Status Code: 200 OK

Success Response Fields

FieldTypeDescription
successbooleanIndicates whether the brand was deleted successfully.
messagestringA message conveying the outcome of the operation, including the brand name.

Example Success Response

{
"success": true,
"message": "Brand Nike deleted successfully"
}

Error Responses

Status CodeDescription
400Bad Request: Provided data is invalid or malformed.
401Unauthorized: Access token is invalid or missing.
404Not Found: Brand with specified ID does not exist.
500Internal Server Error: An error occurred on the server.

Important Notes

Automatic Product Updates

When a brand is deleted, the system automatically:

  1. Unassigns the brand from all associated products - All products that had this brand assigned will have their brand reference removed.
  2. Updates Elasticsearch - All affected products are updated in Elasticsearch to reflect the brand removal.
  3. Maintains data integrity - Ensures no orphaned references remain in the database.

Example Impact

If you delete a brand named "Nike" that has 50 products associated with it:

  • All 50 products will have their brand field set to null
  • All 50 products will be updated in Elasticsearch
  • The brand "Nike" will be completely removed from the system
  • The operation completes in a single transaction

Best Practices

  • Review before deletion: Check how many products are associated with the brand before deleting.
  • Alternative approach: Consider setting isShow: false instead of deleting if you want to hide the brand temporarily.
  • Backup: Ensure you have backups if you need to restore brand data later.

Cannot Be Undone

Brand deletion is permanent and cannot be undone. If you need to restore a deleted brand:

  1. Create a new brand with the same details
  2. Re-assign products to the new brand using the Assign Products to Brand endpoint

Notes

  • Ensure the ID of the brand you wish to delete is valid and exists.
  • You must provide a valid accessToken for authentication.
  • The deletion process is transactional - either everything succeeds or everything fails.