Skip to main content
DELETE
/
api
/
roles
/
:id
Delete Role
curl --request DELETE \
  --url https://api.example.com/api/roles/:id
{
  "success": true,
  "message": "<string>",
  "data": null
}

Overview

Deletes a role from the system. This is a soft delete operation that sets the role status to inactive rather than permanently removing it.
This endpoint requires administrator privileges (role_id: 1). Only admin users can delete roles.

Authentication

Required: Bearer token with admin privileges
Authorization: Bearer <admin_jwt_token>

Path Parameters

id
integer
required
The unique identifier of the role to delete

Response

success
boolean
Indicates if the role was deleted successfully
message
string
Confirmation message
data
null
Always null for delete operations

Examples

curl -X DELETE "http://localhost:4000/api/roles/3" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json"

Response Examples

Success (200 OK)

{
  "success": true,
  "message": "Role deleted successfully",
  "data": null
}

Unauthorized (401)

{
  "success": false,
  "message": "Token no proporcionado o inválido"
}

Forbidden (403)

{
  "success": false,
  "message": "Access denied. Admin privileges required"
}

Not Found (404)

{
  "success": false,
  "message": "Role not found"
}

Error Responses

Status CodeDescription
400Invalid role ID
401Missing or invalid authentication token
403User does not have admin privileges
404Role not found
500Internal server error

Soft Delete Behavior

This endpoint performs a soft delete by setting the role status to “inactive”. The role record remains in the database but is no longer active. This preserves referential integrity with users who may have this role assigned.

Important Notes

Deleting a role that is currently assigned to users may affect their permissions. Ensure you reassign affected users to a different role before deletion.

List Roles

View all roles

Create Role

Create a new role

Update Role

Modify role details

Source Code Reference

  • Route: src/routes/role.routes.js:delete
  • Controller: src/controllers/roleController.js:deleteRole

Build docs developers (and LLMs) love