Trouble Submitting Quiz Attempts in Moodle 4.2.1 via cURL - mod_quiz_save_attempt

102 Views Asked by At

Using Moodle 4.2.1, I'm attempting to submit a quiz attempt via the following curl command, but it's not working as expected. I've tried various examples from ChatGPT and searched for documentation on how to use this API effectively, but I haven't found a clear guide on how to prepare the data for different quiz types such as multiple-choice (single correct answer), multiple-choice (multiple correct answers), true/false, ordering, drag-and-drop words into sentences, short answer, and essay questions. Could someone please assist me in submitting a quiz attempt, or provide a URL to a comprehensive guide that explains how to format the data for these various quiz types in Moodle?

Here's the curl command I'm currently using:

curl --location '/webservice/rest/server.php' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--form 'wstoken="*****"' \
--form 'wsfunction="mod_quiz_save_attempt"' \
--form 'attemptid="24"' \
--form 'data[0][name]="q24:1_:flagged"' \
--form 'data[0][value]="0"' \
--form 'data[1][name]="q24:1_:flagged"' \
--form 'data[1][value]="0"' \
--form 'data[2][name]="q24:1_:sequencecheck"' \
--form 'data[2][value]="2"' \
--form 'data[3][name]="q24:1_answer"' \
--form 'data[3][value]="0"' \
--form 'moodlewsrestformat="json"'

I am having below response with 200 status code, nothing updated in database or nothing changed in quiz attempts on moodle platform

{
    "status": true,
    "warnings": []
}

Any assistance or guidance on this matter would be greatly appreciated.

0

There are 0 best solutions below