Skip to main content

Overview

The Response Options API manages the answer choices associated with questions in the question bank. Response options are used primarily for multiple choice and true/false questions, where each option has text, a correct/incorrect flag, and an optional display order.

Endpoints

List All Response Options

Retrieve all response options in the system.
GET /api/response_option

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Opciones de respuesta listadas con éxito”
data
array
Array of response option objects

Example Request

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

Example Response

{
  "success": true,
  "message": "Opciones de respuesta listadas con éxito",
  "data": [
    {
      "id": 1,
      "preguntas_id": 5,
      "texto": "$variable",
      "es_correcta": 1,
      "orden": 1,
      "created_at": "2026-03-05T10:30:00.000000Z",
      "updated_at": "2026-03-05T10:30:00.000000Z"
    },
    {
      "id": 2,
      "preguntas_id": 5,
      "texto": "var variable",
      "es_correcta": 0,
      "orden": 2,
      "created_at": "2026-03-05T10:30:00.000000Z",
      "updated_at": "2026-03-05T10:30:00.000000Z"
    },
    {
      "id": 3,
      "preguntas_id": 5,
      "texto": "variable:",
      "es_correcta": 0,
      "orden": 3,
      "created_at": "2026-03-05T10:30:00.000000Z",
      "updated_at": "2026-03-05T10:30:00.000000Z"
    },
    {
      "id": 4,
      "preguntas_id": 5,
      "texto": "#variable",
      "es_correcta": 0,
      "orden": 4,
      "created_at": "2026-03-05T10:30:00.000000Z",
      "updated_at": "2026-03-05T10:30:00.000000Z"
    }
  ]
}

Create Response Option

Create a new response option for a question.
POST /api/response_option

Request Body

preguntas_id
integer
required
ID of the question this option belongs to
texto
text
required
The text content of the answer option
es_correcta
tinyint
default:"0"
Flag indicating if this is the correct answer (0 = incorrect, 1 = correct)
orden
smallint
Display order for the option (optional, useful for sequencing)

Response

success
boolean
Indicates if the option was created successfully
message
string
Response message: “Opción de respuesta creada con éxito”
data
object
The created response option object with all fields including timestamps

Example Request

curl -X POST https://api.example.com/api/response_option \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "preguntas_id": 25,
    "texto": "El operador punto (.)",
    "es_correcta": 1,
    "orden": 1
  }'

Example Response

{
  "success": true,
  "message": "Opción de respuesta creada con éxito",
  "data": {
    "id": 87,
    "preguntas_id": 25,
    "texto": "El operador punto (.)",
    "es_correcta": 1,
    "orden": 1,
    "created_at": "2026-03-05T14:25:00.000000Z",
    "updated_at": "2026-03-05T14:25:00.000000Z"
  }
}

Get Response Option

Retrieve a specific response option by ID.
GET /api/response_option/{id}

Path Parameters

id
integer
required
The unique identifier of the response option

Response

success
boolean
Indicates if the request was successful
message
string
Response message: “Opción de respuesta obtenida con éxito”
data
object
The response option object with all fields

Example Request

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

Example Response

{
  "success": true,
  "message": "Opción de respuesta obtenida con éxito",
  "data": {
    "id": 87,
    "preguntas_id": 25,
    "texto": "El operador punto (.)",
    "es_correcta": 1,
    "orden": 1,
    "created_at": "2026-03-05T14:25:00.000000Z",
    "updated_at": "2026-03-05T14:25:00.000000Z"
  }
}

Update Response Option

Update an existing response option.
PUT /api/response_option/{id}

Path Parameters

id
integer
required
The unique identifier of the response option to update

Request Body

preguntas_id
integer
ID of the question this option belongs to
texto
text
The text content of the answer option
es_correcta
tinyint
Correct answer flag (0 or 1)
orden
smallint
Display order

Response

success
boolean
Indicates if the update was successful
message
string
Response message: “Opción de respuesta actualizada con éxito”
data
object
The updated response option object

Example Request

curl -X PUT https://api.example.com/api/response_option/87 \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "texto": "El operador punto (.) para concatenación",
    "orden": 1
  }'

Example Response

{
  "success": true,
  "message": "Opción de respuesta actualizada con éxito",
  "data": {
    "id": 87,
    "preguntas_id": 25,
    "texto": "El operador punto (.) para concatenación",
    "es_correcta": 1,
    "orden": 1,
    "created_at": "2026-03-05T14:25:00.000000Z",
    "updated_at": "2026-03-05T15:18:00.000000Z"
  }
}

Delete Response Option

Delete a response option from the system.
DELETE /api/response_option/{id}

Path Parameters

id
integer
required
The unique identifier of the response option to delete

Response

success
boolean
Indicates if the deletion was successful
message
string
Response message: “Opción de respuesta eliminada con éxito”
data
null
Returns null after successful deletion

Example Request

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

Example Response

{
  "success": true,
  "message": "Opción de respuesta eliminada con éxito",
  "data": null
}

Foreign Key Relationships

Question Relationship

  • Field: preguntas_id
  • References: preguntas.id
  • On Delete: CASCADE (deleting a question will delete all its response options)

Important Notes

Route Name

Note that the API route is /api/response_option (singular), not /api/response_options (plural).

Usage Guidelines

  • Each question can have multiple response options
  • For multiple choice questions, typically 4-5 options are created
  • For true/false questions, exactly 2 options should be created
  • Only one option should have es_correcta set to 1 for single-answer questions
  • Multiple options can be correct for multi-select questions
  • The orden field allows control over how options are displayed to users
  • Response options use timestamps (created_at, updated_at) for audit tracking

Best Practices

  1. Ordering: Use the orden field to control the sequence of display
  2. Validation: Ensure at least one option is marked as correct for each question
  3. Text Length: Keep option text concise and clear
  4. Cascading Deletes: Be aware that deleting a question will automatically delete all its response options

Example: Creating a Complete Multiple Choice Question

Here’s a workflow for creating a multiple choice question with options:
# Step 1: Create the question
curl -X POST https://api.example.com/api/questions \
  -H "Content-Type: application/json" \
  -d '{
    "tema_id": 8,
    "tipo": "opcion_multiple",
    "enunciado": "¿Cuál es la forma correcta de declarar una variable en PHP?",
    "puntaje": 1.00,
    "nivel_dificultad": 1
  }'

# Response: { "data": { "id": 50, ... } }

# Step 2: Create response options
curl -X POST https://api.example.com/api/response_option \
  -H "Content-Type: application/json" \
  -d '{"preguntas_id": 50, "texto": "$variable", "es_correcta": 1, "orden": 1}'

curl -X POST https://api.example.com/api/response_option \
  -H "Content-Type: application/json" \
  -d '{"preguntas_id": 50, "texto": "var variable", "es_correcta": 0, "orden": 2}'

curl -X POST https://api.example.com/api/response_option \
  -H "Content-Type: application/json" \
  -d '{"preguntas_id": 50, "texto": "variable:", "es_correcta": 0, "orden": 3}'

curl -X POST https://api.example.com/api/response_option \
  -H "Content-Type: application/json" \
  -d '{"preguntas_id": 50, "texto": "#variable", "es_correcta": 0, "orden": 4}'

Build docs developers (and LLMs) love