Moodle API Quizzes - C0D3D3V/Moodle-DL GitHub Wiki
To download quizzes the following functions are of interest:
| Area | Name | Introduced in | Description | 
|---|---|---|---|
| mod_quiz | mod_quiz_get_quizzes_by_courses | 3.1 (2016052300) | Returns a list of quizzes in a provided list of courses, if no list is provided all quizzes that the user can view will be returned. | 
| mod_quiz | mod_quiz_get_user_attempts | 3.1 (2016052300) | Return a list of attempts for the given quiz and user. | 
| mod_quiz | mod_quiz_get_attempt_summary | 3.1 (2016052300) | Returns a summary of a quiz attempt before it is submitted. | 
| mod_quiz | mod_quiz_get_attempt_review | 3.1 (2016052300) | Returns review information for the given finished attempt, can be used by users or teachers. | 
Quizzes are part of the course content.
An example module which returns core_course_get_contents:
{
    "id": 59,
    "url": "http://10.111.0.107/moodle/mod/quiz/view.php?id=59",
    "name": "Super Quiz",
    "instance": 1,
    "contextid": 104,
    "visible": 1,
    "uservisible": true,
    "visibleoncoursepage": 1,
    "modicon": "http://10.111.0.107/moodle/theme/image.php/boost/quiz/1633802793/icon",
    "modname": "quiz",
    "modplural": "Tests",
    "availability": null,
    "indent": 0,
    "onclick": "",
    "afterlink": null,
    "customdata": "\"\"",
    "noviewlink": false,
    "completion": 1,
    "completiondata": {
        "state": 0,
        "timecompleted": 0,
        "overrideby": null,
        "valueused": false
    }
}
The module indicates where the quiz is located in the course, nothing more can be derived from it.
Load a list of all quizzes
mod_quiz_get_quizzes_by_courses
With the help of mod_quiz_get_quizzes_by_courses all quizzes-id's of all courses can be loaded. It exists since Version 3.1. The function takes the following arguments:
courseidsis an array of the course-ids from which the quizzes are to be loaded.
mod_quiz_get_quizzes_by_courses returns a list of quizzes:
{
    "quizzes": [
        {
            "id": 1,
            "course": 3,
            "coursemodule": 59,
            "name": "Super Quiz",
            "intro": "",
            "introformat": 1,
            "introfiles": [],
            "timeopen": 1633951500,
            "timeclose": 1633971060,
            "timelimit": 300,
            "overduehandling": "autosubmit",
            "graceperiod": 0,
            "preferredbehaviour": "immediatefeedback",
            "canredoquestions": 0,
            "attempts": 1,
            "attemptonlast": 0,
            "grademethod": 1,
            "decimalpoints": 2,
            "questiondecimalpoints": -1,
            "reviewattempt": 69904,
            "reviewcorrectness": 4352,
            "reviewmarks": 4352,
            "reviewspecificfeedback": 4352,
            "reviewgeneralfeedback": 4352,
            "reviewrightanswer": 4352,
            "reviewoverallfeedback": 4352,
            "questionsperpage": 1,
            "navmethod": "free",
            "sumgrades": 10,
            "grade": 10,
            "browsersecurity": "-",
            "delay1": 0,
            "delay2": 0,
            "showuserpicture": 0,
            "showblocks": 0,
            "completionattemptsexhausted": 0,
            "completionpass": 0,
            "allowofflineattempts": 0,
            "autosaveperiod": 60,
            "hasfeedback": 0,
            "hasquestions": 1,
            "section": 1,
            "visible": 1,
            "groupmode": 0,
            "groupingid": 0
        }
    ],
    "warnings": []
}
Important attributes:
courseis the id of the course the quiz belongs to.idis the id of the quizcoursemoduleis the module id that was returned bycore_course_get_contentsnameis the name of the quiz
Load a list of all attempts of a quiz
mod_quiz_get_user_attempts
To get a list of all questions in the attempt there are two functions. mod_quiz_get_attempt_summary is used if state="inprogress" and mod_quiz_get_attempt_review is used if state="finished". Both functions work identically and return in questions all questions.
mod_quiz_get_attempt_summary
mod_quiz_get_attempt_review
To finally download all quizzes you need to merge all questions into one HTML file and add a stylesheed (https://your.moodle/theme/styles.php/boost/-1/all)