quiz object methods - get question groups #591
Replies: 1 comment 2 replies
-
Alas, ChatGPT offers seemingly correct answers that are, in fact, 100% incorrect. You're right - there is no In Canvas, Question Groups don't exist until a student has made a submission and, at that point, they only exist on that submission. The question groups are not present at all if you try to access the quiz directly to get group IDs. I confirmed this by making a quiz with one question and one group linked to a question bank. Calling [
{
"id":870320,
"quiz_id":76191,
"quiz_group_id":null,
"assessment_question_id":1052946,
"position":null,
"question_name":"Question",
"question_type":"essay_question",
"question_text":"This is the question",
"points_possible":1.0,
// ... the rest of the properties
}
] This confirmed that my question group is not included becase, at the point of creation, there are no questions in the group. Questions are selected from the attached bank at the moment a student opens the assessment. It seems, according to this lengthy answer in the community forums, that the only way to get question group IDs via the API is to look at a student submission. I'm saying this having read James' post in the community, but I have not tried it myself, so I cannot guarantee that the question group IDs you get using this method are the same for all students in the course. To summarize James' solution (the thread is worth reading even though the code syntax got all borked when Instructure changed their forum platform), once a student has taken the assessment, you can use the Submissons endpoint to get the student submission which can then give you access to some details on the questions. The steps are:
In the library, your script would look something like this: # imports and Canvas init
course = canvas.get_course(1)
submissions = course.get_quiz(2).get_submissions()
for sub in submissions:
# use the current submission ID to get the individual quiz
quiz_submission = quiz.get_quiz_submission(sub.id)
# Now you have a QuizSubmission class with a method to get all of the questions for that attempt
questions = quiz_submission.get_submission_questions()
# questions is a list of QuizSubmissionQuestion objects that you can finally get the group ID on
for item in questions:
if item.quiz_group_id is not None:
group = quiz.get_quiz_group(item.quiz_group_id)
# do stuff I hope this helps you come up with a working solution. It definitely needs to be explored whether or not different submissions by different students show the same group IDs for the submissions. Please leave an update with what you learn! |
Beta Was this translation helpful? Give feedback.
-
I have been using canvasapi for a bit over a year now, quite successfully. Amazing work. You have my eternal gratitude.
Recently, I have been working on an application to aid with managing quiz content. While I am able to perform quite a number of operations, it has become apparent that it would be useful to be able to obtain information on all the question groups in any given quiz (classic). I know that there is a ".get_quiz_group()" method for the "Quiz" class, and I know there is a "QuizGroup" class which provides some very useful functions; however, it appears that the question group ID is necessary to begin specifying a particular question group. I have been through the documentation (and even peeked at the python source) to see if I may be missing something, but is there a method for obtaining question group IDs (or other general information on question groups) using this library? (On the other hand, I have been able to create new questions groups within a quiz, and that has been extremely helpful, thank you very much.)
Interestingly, I have gone so far as to query ChatGPT, and it unabashedly informed me that there is a ".get_question_groups()" method for a quiz object. While it sounded quite promising, and I have updated to the latest version of canvasapi, this particular method seems to elude my awareness. I know ChatGPT is not perfect, but it sounded very convincing in this matter.
Any insight would be greatly appreciated. Thank you.
Beta Was this translation helpful? Give feedback.
All reactions