Opciones API
The Opciones (Options/Actions) endpoint manages action-level entries in the hierarchical permission system. Opciones belong to Vistas and represent specific actions users can perform.
Hierarchy
Menu (Top Level)
└── Vista (Views within menu)
└── Opciones (Actions within view) ← Current Level
Model Structure
The Opciones model represents the lowest level of the permission hierarchy, defining specific actions available within a Vista.
Fields
Auto-incremented primary key identifying the opcion
Foreign key reference to the parent Vista
Name of the action/option (max 40 characters)
Examples: “Crear”, “Editar”, “Eliminar”, “Ver”, “Exportar”
Description of the action’s purpose (max 40 characters)
Endpoints
List All Opciones
Retrieve all opciones in the system.
Query Parameters
Filter opciones by vista ID
Filter by status (0: Inactive, 1: Active)
Response
Unique identifier for the opcion
Example Response
{
"results": [
{
"id_opcion": 1,
"id_vista": 2,
"nombre_vista": "Crear",
"descripcion": "Create new campaign",
"estado": 1
},
{
"id_opcion": 2,
"id_vista": 2,
"nombre_vista": "Editar",
"descripcion": "Edit existing campaign",
"estado": 1
},
{
"id_opcion": 3,
"id_vista": 2,
"nombre_vista": "Eliminar",
"descripcion": "Delete campaign",
"estado": 1
},
{
"id_opcion": 4,
"id_vista": 2,
"nombre_vista": "Ver",
"descripcion": "View campaign details",
"estado": 1
}
]
}
Get Opcion by ID
GET /api/opciones/{id_opcion}/
Retrieve details of a specific opcion.
Path Parameters
The unique identifier of the opcion
Response
Unique identifier for the opcion
Example Response
{
"id_opcion": 1,
"id_vista": 2,
"nombre_vista": "Crear",
"descripcion": "Create new campaign",
"estado": 1
}
Get Opciones by Vista
GET /api/opciones/?id_vista={id_vista}
Retrieve all opciones belonging to a specific vista.
Example Response
{
"results": [
{
"id_opcion": 1,
"id_vista": 2,
"nombre_vista": "Crear",
"descripcion": "Create new campaign",
"estado": 1
},
{
"id_opcion": 2,
"id_vista": 2,
"nombre_vista": "Editar",
"descripcion": "Edit existing campaign",
"estado": 1
}
]
}
Create Opcion
Create a new action option within a vista.
Request Body
The ID of the parent vista
Name of the action (max 40 characters)
Description of the action (max 40 characters)
Status of the action (0: Inactive, 1: Active)
Example Request
{
"id_vista": 2,
"nombre_vista": "Exportar",
"descripcion": "Export campaign data",
"estado": 1
}
Response
The ID of the newly created opcion
Update Opcion
PUT /api/opciones/{id_opcion}/
PATCH /api/opciones/{id_opcion}/
Update an existing opcion. Use PUT for full updates or PATCH for partial updates.
Path Parameters
The unique identifier of the opcion to update
Request Body
Delete Opcion
DELETE /api/opciones/{id_opcion}/
Delete an opcion from the system.
Path Parameters
The unique identifier of the opcion to delete
Complete Hierarchy Example
Here’s a complete example showing the full permission hierarchy:
{
"menu": {
"id_menu": 2,
"nombre_menu": "Campañas",
"descripcion": "Campaign management",
"vistas": [
{
"id_vista": 2,
"nombre_vista": "Gestión de Campañas",
"descripcion": "Manage campaigns",
"opciones": [
{
"id_opcion": 1,
"nombre_vista": "Crear",
"descripcion": "Create new campaign"
},
{
"id_opcion": 2,
"nombre_vista": "Editar",
"descripcion": "Edit campaign"
},
{
"id_opcion": 3,
"nombre_vista": "Eliminar",
"descripcion": "Delete campaign"
},
{
"id_opcion": 4,
"nombre_vista": "Ver",
"descripcion": "View campaign details"
}
]
},
{
"id_vista": 3,
"nombre_vista": "Estadísticas",
"descripcion": "Campaign statistics",
"opciones": [
{
"id_opcion": 5,
"nombre_vista": "Ver Reportes",
"descripcion": "View campaign reports"
},
{
"id_opcion": 6,
"nombre_vista": "Exportar",
"descripcion": "Export statistics"
}
]
}
]
}
}
Common Action Names
Typical action names used in the system:
- Crear - Create new records
- Editar - Edit existing records
- Eliminar - Delete records
- Ver - View/read records
- Exportar - Export data
- Importar - Import data
- Aprobar - Approve records
- Rechazar - Reject records
Usage Notes
- Opciones must belong to a valid Vista (id_vista foreign key)
- Each opcion represents a specific action within a vista
- Use DetallePermisos to control whether specific opciones are allowed for a role
- Set estado to 0 to disable an action rather than deleting it
- Action names should be consistent across similar vistas for better UX