Skip to main content

Overview

The Questions API manages the question bank used for creating assessments and evaluations. Questions can be of different types (multiple choice, true/false, short answer, calculation) and are associated with specific topics. Each question has configurable difficulty levels, point values, and optional explanations.

Endpoints

List All Questions

Retrieve all questions in the question bank.
GET /api/questions

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Preguntas listadas con éxito”
data
array
Array of question objects

Example Request

curl -X GET https://api.example.com/api/questions \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Preguntas listadas con éxito",
  "data": [
    {
      "id": 1,
      "tema_id": 8,
      "docente_id": 12,
      "tipo": "opcion_multiple",
      "enunciado": "¿Cuál es la forma correcta de declarar una variable en PHP?",
      "imagen_url": null,
      "puntaje": "1.00",
      "nivel_dificultad": 1,
      "explicacion": "En PHP, las variables se declaran con el símbolo $ seguido del nombre de la variable",
      "activo": 1,
      "created_at": "2026-03-05T10:30:00.000000Z",
      "updated_at": "2026-03-05T10:30:00.000000Z"
    },
    {
      "id": 2,
      "tema_id": 8,
      "docente_id": 12,
      "tipo": "verdadero_falso",
      "enunciado": "PHP es un lenguaje de programación compilado",
      "imagen_url": null,
      "puntaje": "0.50",
      "nivel_dificultad": 1,
      "explicacion": "Falso. PHP es un lenguaje interpretado, no compilado",
      "activo": 1,
      "created_at": "2026-03-05T10:35:00.000000Z",
      "updated_at": "2026-03-05T10:35:00.000000Z"
    }
  ]
}

Create Question

Create a new question in the question bank.
POST /api/questions

Request Body

tema_id
integer
required
ID of the topic this question belongs to
docente_id
integer
ID of the instructor creating this question (optional)
tipo
enum
required
Type of question. Must be one of: opcion_multiple, verdadero_falso, respuesta_corta, calculo
enunciado
text
required
The question statement or prompt
imagen_url
string
URL to an image for the question (maximum 500 characters, optional)
puntaje
decimal
default:"1.00"
Point value for this question (format: 999.99)
nivel_dificultad
smallint
default:"1"
Difficulty level (typically 1-5, where 1 is easiest)
explicacion
text
Explanation for the correct answer (optional)
activo
tinyint
default:"1"
Active status (0 = inactive, 1 = active)

Response

success
boolean
Indicates if the question was created successfully
message
string
Response message: “Pregunta creada con éxito”
data
object
The created question object with all fields including timestamps

Example Request

curl -X POST https://api.example.com/api/questions \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "tema_id": 8,
    "docente_id": 12,
    "tipo": "opcion_multiple",
    "enunciado": "¿Qué operador se utiliza para concatenar cadenas en PHP?",
    "imagen_url": null,
    "puntaje": 1.50,
    "nivel_dificultad": 2,
    "explicacion": "El operador punto (.) se utiliza para concatenar strings en PHP",
    "activo": 1
  }'

Example Response

{
  "success": true,
  "message": "Pregunta creada con éxito",
  "data": {
    "id": 25,
    "tema_id": 8,
    "docente_id": 12,
    "tipo": "opcion_multiple",
    "enunciado": "¿Qué operador se utiliza para concatenar cadenas en PHP?",
    "imagen_url": null,
    "puntaje": "1.50",
    "nivel_dificultad": 2,
    "explicacion": "El operador punto (.) se utiliza para concatenar strings en PHP",
    "activo": 1,
    "created_at": "2026-03-05T14:22:00.000000Z",
    "updated_at": "2026-03-05T14:22:00.000000Z"
  }
}

Get Question

Retrieve a specific question by ID.
GET /api/questions/{id}

Path Parameters

id
integer
required
The unique identifier of the question

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Pregunta obtenida con éxito”
data
object
The question object with all fields

Example Request

curl -X GET https://api.example.com/api/questions/25 \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Pregunta obtenida con éxito",
  "data": {
    "id": 25,
    "tema_id": 8,
    "docente_id": 12,
    "tipo": "opcion_multiple",
    "enunciado": "¿Qué operador se utiliza para concatenar cadenas en PHP?",
    "imagen_url": null,
    "puntaje": "1.50",
    "nivel_dificultad": 2,
    "explicacion": "El operador punto (.) se utiliza para concatenar strings en PHP",
    "activo": 1,
    "created_at": "2026-03-05T14:22:00.000000Z",
    "updated_at": "2026-03-05T14:22:00.000000Z"
  }
}

Update Question

Update an existing question.
PUT /api/questions/{id}

Path Parameters

id
integer
required
The unique identifier of the question to update

Request Body

tema_id
integer
ID of the topic this question belongs to
docente_id
integer
ID of the instructor
tipo
enum
Type of question: opcion_multiple, verdadero_falso, respuesta_corta, or calculo
enunciado
text
The question statement
imagen_url
string
URL to an associated image (maximum 500 characters)
puntaje
decimal
Point value (format: 999.99)
nivel_dificultad
smallint
Difficulty level
explicacion
text
Explanation for the correct answer
activo
tinyint
Active status (0 or 1)

Response

success
boolean
Indicates if the update was successful
message
string
Response message: “Pregunta actualizada con éxito”
data
object
The updated question object

Example Request

curl -X PUT https://api.example.com/api/questions/25 \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "puntaje": 2.00,
    "nivel_dificultad": 3,
    "explicacion": "El operador punto (.) se utiliza para concatenar strings en PHP. Ejemplo: $nombre . $apellido"
  }'

Example Response

{
  "success": true,
  "message": "Pregunta actualizada con éxito",
  "data": {
    "id": 25,
    "tema_id": 8,
    "docente_id": 12,
    "tipo": "opcion_multiple",
    "enunciado": "¿Qué operador se utiliza para concatenar cadenas en PHP?",
    "imagen_url": null,
    "puntaje": "2.00",
    "nivel_dificultad": 3,
    "explicacion": "El operador punto (.) se utiliza para concatenar strings en PHP. Ejemplo: $nombre . $apellido",
    "activo": 1,
    "created_at": "2026-03-05T14:22:00.000000Z",
    "updated_at": "2026-03-05T15:10:00.000000Z"
  }
}

Delete Question

Delete a question from the question bank.
DELETE /api/questions/{id}

Path Parameters

id
integer
required
The unique identifier of the question to delete

Response

success
boolean
Indicates if the deletion was successful
message
string
Response message: “Pregunta eliminada con éxito”
data
null
Returns null after successful deletion

Example Request

curl -X DELETE https://api.example.com/api/questions/25 \
  -H "Accept: application/json"

Example Response

{
  "success": true,
  "message": "Pregunta eliminada con éxito",
  "data": null
}

Foreign Key Relationships

Topic Relationship

  • Field: tema_id
  • References: topics.id
  • On Delete: CASCADE (deleting a topic will delete all associated questions)

Instructor Relationship

  • Field: docente_id
  • References: users.id
  • On Delete: SET NULL (deleting a user will set the field to null, preserving the question)

Question Types

The tipo field supports four question types:
  • opcion_multiple: Multiple choice questions with several answer options
  • verdadero_falso: True/false questions
  • respuesta_corta: Short answer questions requiring text input
  • calculo: Calculation questions requiring numeric answers

Notes

  • Questions use timestamps (created_at, updated_at) for audit tracking
  • The puntaje field allows decimal values for flexible grading (e.g., 1.50, 2.00)
  • Difficulty levels typically range from 1 (easiest) to 5 (hardest)
  • Questions can be soft-deleted by setting activo to 0
  • The imagen_url field allows adding visual elements to questions
  • Each question must be associated with a valid topic via tema_id
  • The explicacion field is useful for providing feedback after answering

Build docs developers (and LLMs) love