Skip to content

Quizzes API [PRO]

PRO FEATURE

This feature is only available in Fluent Community Pro.

Quizzes allow you to add assessments to course lessons, test student knowledge, and track learning progress. Students can submit quiz answers and view their results.


Quiz Object

json
{
  "id": 1,
  "user_id": 42,
  "course_id": 5,
  "lesson_id": 15,
  "answers": {
    "question_1": "option_a",
    "question_2": "option_c",
    "question_3": ["option_a", "option_b"]
  },
  "score": 85,
  "total_questions": 10,
  "correct_answers": 8,
  "passed": true,
  "passing_score": 70,
  "attempt_number": 1,
  "time_spent": 420,
  "status": "completed",
  "submitted_at": "2024-01-20 14:30:00",
  "graded_at": "2024-01-20 14:30:05",
  "feedback": "Great job! You passed the quiz."
}

Attributes

AttributeTypeDescription
idintegerUnique identifier for the quiz submission
user_idintegerID of the student who took the quiz
course_idintegerID of the course
lesson_idintegerID of the lesson containing the quiz
answersobjectStudent's submitted answers
scoreintegerPercentage score (0-100)
total_questionsintegerTotal number of questions
correct_answersintegerNumber of correct answers
passedbooleanWhether the student passed
passing_scoreintegerMinimum score required to pass
attempt_numberintegerWhich attempt this is (if retakes allowed)
time_spentintegerTime spent in seconds
statusstringin_progress, completed, graded
submitted_atdatetimeWhen the quiz was submitted
graded_atdatetimeWhen the quiz was graded
feedbackstringInstructor feedback or auto-generated message

Quiz Question Object

json
{
  "id": "question_1",
  "type": "multiple_choice",
  "question": "What is the capital of France?",
  "options": [
    {
      "id": "option_a",
      "text": "Paris",
      "is_correct": true
    },
    {
      "id": "option_b",
      "text": "London",
      "is_correct": false
    },
    {
      "id": "option_c",
      "text": "Berlin",
      "is_correct": false
    }
  ],
  "points": 10,
  "explanation": "Paris is the capital and largest city of France."
}

Question Types

TypeDescription
multiple_choiceSingle correct answer from multiple options
multiple_selectMultiple correct answers possible
true_falseTrue or false question
short_answerText-based answer (manual grading)

Submit Quiz

Submit quiz answers for grading.

HTTP Request

POST /wp-json/fluent-community/v2/courses/{course_id}/lessons/{lesson_id}/quiz/submit

URL Parameters

ParameterTypeDescription
course_idintegerThe ID of the course
lesson_idintegerThe ID of the lesson with the quiz

Request Body

ParameterTypeRequiredDescription
answersobjectYesQuiz answers keyed by question ID
time_spentintegerNoTime spent on quiz in seconds

Example Request

bash
curl -X POST "https://example.com/wp-json/fluent-community/v2/courses/5/lessons/15/quiz/submit" \
  -u "username:password" \
  -H "Content-Type: application/json" \
  -d '{
    "answers": {
      "question_1": "option_a",
      "question_2": "option_c",
      "question_3": ["option_a", "option_b"],
      "question_4": "true"
    },
    "time_spent": 420
  }'

Example Response

json
{
  "message": "Quiz submitted successfully",
  "quiz_result": {
    "id": 123,
    "score": 85,
    "total_questions": 10,
    "correct_answers": 8,
    "passed": true,
    "passing_score": 70,
    "attempt_number": 1,
    "feedback": "Congratulations! You passed the quiz with 85%.",
    "can_retake": false,
    "next_lesson_unlocked": true,
    "submitted_at": "2024-01-20 14:30:00"
  },
  "detailed_results": [
    {
      "question_id": "question_1",
      "question": "What is the capital of France?",
      "your_answer": "option_a",
      "correct_answer": "option_a",
      "is_correct": true,
      "points_earned": 10,
      "points_possible": 10,
      "explanation": "Paris is the capital and largest city of France."
    },
    {
      "question_id": "question_2",
      "question": "Which planet is closest to the Sun?",
      "your_answer": "option_c",
      "correct_answer": "option_b",
      "is_correct": false,
      "points_earned": 0,
      "points_possible": 10,
      "explanation": "Mercury is the closest planet to the Sun."
    }
  ]
}

Get Quiz Result

Retrieve the result of a previously submitted quiz.

HTTP Request

GET /wp-json/fluent-community/v2/courses/{course_id}/lessons/{lesson_id}/quiz/result

URL Parameters

ParameterTypeDescription
course_idintegerThe ID of the course
lesson_idintegerThe ID of the lesson with the quiz

Query Parameters

ParameterTypeDefaultDescription
attemptintegerlatestWhich attempt to retrieve (1, 2, 3, or "latest")
include_answersbooleantrueInclude detailed answer breakdown

Example Request

bash
curl -X GET "https://example.com/wp-json/fluent-community/v2/courses/5/lessons/15/quiz/result?attempt=latest" \
  -u "username:password"

Example Response

json
{
  "quiz_result": {
    "id": 123,
    "user_id": 42,
    "course_id": 5,
    "lesson_id": 15,
    "score": 85,
    "total_questions": 10,
    "correct_answers": 8,
    "passed": true,
    "passing_score": 70,
    "attempt_number": 1,
    "time_spent": 420,
    "status": "completed",
    "submitted_at": "2024-01-20 14:30:00",
    "graded_at": "2024-01-20 14:30:05",
    "feedback": "Congratulations! You passed the quiz with 85%."
  },
  "quiz_settings": {
    "max_attempts": 3,
    "attempts_used": 1,
    "can_retake": true,
    "time_limit": 1800,
    "show_correct_answers": true,
    "randomize_questions": false
  },
  "detailed_results": [
    {
      "question_id": "question_1",
      "question": "What is the capital of France?",
      "your_answer": "option_a",
      "correct_answer": "option_a",
      "is_correct": true,
      "points_earned": 10,
      "points_possible": 10
    }
  ]
}

Get Course Quiz Results (Admin)

Retrieve all quiz results for a course. Admin only.

HTTP Request

GET /wp-json/fluent-community/v2/admin/courses/{course_id}/quiz-results

URL Parameters

ParameterTypeDescription
course_idintegerThe ID of the course

Query Parameters

ParameterTypeDefaultDescription
lesson_idintegernullFilter by specific lesson
user_idintegernullFilter by specific student
statusstringallFilter by status: all, passed, failed
pageinteger1Page number for pagination
per_pageinteger20Results per page
orderbystringsubmitted_atSort by: submitted_at, score, user_name
orderstringdescSort order: asc, desc

Example Request

bash
curl -X GET "https://example.com/wp-json/fluent-community/v2/admin/courses/5/quiz-results?status=passed&per_page=10" \
  -u "username:password"

Example Response

json
{
  "quiz_results": [
    {
      "id": 123,
      "xprofile": {
        "user_id": 42,
        "total_points": 6425,
        "is_verified": 1,
        "status": "active",
        "display_name": "User Name",
        "username": "username",
        "avatar": "avatar_url",
        "created_at": "2024-03-05 16:37:02",
        "short_description": "User description",
        "meta": {
          "website": "website_url",
          "cover_photo": "cover_photo_url",
          "social_links": {
            "twitter": "@handle",
            "youtube": "@handle",
            "linkedin": "handle",
            "fb": "handle",
            "instagram": "handle"
          },
          "badge_slug": ["badge1", "badge2"]
        },
        "badge": null
      },
      "lesson": {
        "id": 15,
        "title": "Introduction to JavaScript",
        "slug": "intro-javascript"
      },
      "score": 85,
      "total_questions": 10,
      "correct_answers": 8,
      "passed": true,
      "attempt_number": 1,
      "time_spent": 420,
      "submitted_at": "2024-01-20 14:30:00"
    },
    {
      "id": 124,
      "xprofile": {
        "user_id": 43,
        "total_points": 3210,
        "is_verified": 0,
        "status": "active",
        "display_name": "User Name",
        "username": "username",
        "avatar": "avatar_url",
        "created_at": "2024-03-05 16:37:02",
        "short_description": "User description",
        "meta": {
          "website": "website_url",
          "cover_photo": "cover_photo_url",
          "social_links": {
            "twitter": "@handle",
            "youtube": "@handle",
            "linkedin": "handle",
            "fb": "handle",
            "instagram": "handle"
          },
          "badge_slug": ["badge1", "badge2"]
        },
        "badge": null
      },
      "lesson": {
        "id": 15,
        "title": "Introduction to JavaScript",
        "slug": "intro-javascript"
      },
      "score": 92,
      "total_questions": 10,
      "correct_answers": 9,
      "passed": true,
      "attempt_number": 1,
      "time_spent": 380,
      "submitted_at": "2024-01-20 15:15:00"
    }
  ],
  "pagination": {
    "total": 45,
    "per_page": 10,
    "current_page": 1,
    "total_pages": 5
  },
  "statistics": {
    "total_submissions": 45,
    "passed": 38,
    "failed": 7,
    "average_score": 78.5,
    "average_time": 425
  }
}

Update Quiz Result (Admin)

Manually update or grade a quiz result. Admin only.

HTTP Request

POST /wp-json/fluent-community/v2/admin/courses/{course_id}/quiz-results/{quiz_id}

URL Parameters

ParameterTypeDescription
course_idintegerThe ID of the course
quiz_idintegerThe ID of the quiz result

Request Body

ParameterTypeRequiredDescription
scoreintegerNoOverride score (0-100)
passedbooleanNoOverride pass/fail status
feedbackstringNoInstructor feedback
answersobjectNoUpdate specific answer grades

Example Request

bash
curl -X POST "https://example.com/wp-json/fluent-community/v2/admin/courses/5/quiz-results/123" \
  -u "username:password" \
  -H "Content-Type: application/json" \
  -d '{
    "score": 90,
    "passed": true,
    "feedback": "Excellent work! I gave you extra credit for your detailed short answer."
  }'

Example Response

json
{
  "message": "Quiz result updated successfully",
  "quiz_result": {
    "id": 123,
    "score": 90,
    "passed": true,
    "feedback": "Excellent work! I gave you extra credit for your detailed short answer.",
    "graded_at": "2024-01-21 10:00:00",
    "graded_by": {
      "id": 1,
      "display_name": "Admin User"
    }
  }
}

Best Practices

Quiz Design

  • Clear Questions: Write unambiguous questions with clear correct answers
  • Appropriate Difficulty: Match quiz difficulty to lesson content
  • Balanced Distribution: Mix question types for comprehensive assessment
  • Meaningful Feedback: Provide explanations for both correct and incorrect answers

Grading Configuration

json
{
  "passing_score": 70,        // 70% required to pass
  "max_attempts": 3,          // Allow 3 attempts
  "show_correct_answers": true, // Show answers after submission
  "time_limit": 1800          // 30 minutes time limit
}

Student Experience

  • Progress Tracking: Show quiz completion in course progress
  • Immediate Feedback: Auto-grade when possible for instant results
  • Retake Options: Allow retakes for learning reinforcement
  • Clear Requirements: Display passing score and attempt limits upfront

Common Use Cases

1. Check Student Progress

bash
# Get all quiz results for a course
curl -X GET ".../admin/courses/5/quiz-results?orderby=score&order=desc"

# Filter by specific student
curl -X GET ".../admin/courses/5/quiz-results?user_id=42"

2. Manual Grading

bash
# Grade a short answer question
curl -X POST ".../admin/courses/5/quiz-results/123" \
  -d '{
    "score": 95,
    "feedback": "Excellent analysis of the topic!"
  }'

3. Student Retakes Quiz

bash
# Submit new attempt
curl -X POST ".../courses/5/lessons/15/quiz/submit" \
  -d '{"answers": {...}}'

# View latest result
curl -X GET ".../courses/5/lessons/15/quiz/result?attempt=latest"

Error Handling

Common Errors

404 Not Found

json
{
  "code": "quiz_not_found",
  "message": "No quiz found for this lesson"
}

400 Bad Request

json
{
  "code": "invalid_answers",
  "message": "Missing required answers for questions: question_1, question_3"
}

403 Forbidden

json
{
  "code": "max_attempts_reached",
  "message": "You have used all 3 attempts for this quiz"
}

409 Conflict

json
{
  "code": "already_submitted",
  "message": "You have already submitted this quiz. Use retake if allowed."
}

Fluent Community developer documentation