Skip to main content

POST /api/roles//permissions/

Assigns an existing permission to a role. Once assigned, all users with this role will gain the associated permission.

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header.

Path Parameters

id
UUID
required
The unique identifier of the role to which the permission will be assigned
permissionId
UUID
required
The unique identifier of the permission to assign to the role

Response

This endpoint returns 204 No Content on success with an empty response body.

Error Responses

  • 404 Not Found: Role or permission with the specified ID does not exist
  • 409 Conflict: The permission is already assigned to this role
  • 500 Internal Server Error: Unexpected server error

Example Request

curl -X POST https://api.example.com/api/roles/550e8400-e29b-41d4-a716-446655440000/permissions/660e8400-e29b-41d4-a716-446655440001 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Example Success Response

HTTP/1.1 204 No Content

Example Error Response (Not Found)

{
  "timestamp": "2024-01-15T10:30:00Z",
  "requestId": "abc-123-def",
  "message": "Resource not found",
  "detail": "Permission with ID 660e8400-e29b-41d4-a716-446655440001 does not exist"
}

Example Error Response (Conflict)

{
  "timestamp": "2024-01-15T10:30:00Z",
  "requestId": "abc-123-def",
  "message": "Permission already assigned",
  "detail": "The permission is already assigned to this role"
}

Usage Notes

  • Both the role and permission must exist before assignment
  • Attempting to assign the same permission twice will result in a 409 Conflict error
  • Users with this role will immediately gain access to the new permission
  • This action is logged in the audit trail with action type ASIGNAR_PERMISO
  • Verify permission requirements before assignment to avoid over-privileging

Build docs developers (and LLMs) love