Re: Classifying answered quiz items based on the question group

Jump to solution
Community Member

Good day!

I made a quiz in canvas which was randomized. I made several question groups during the construction of the quiz to have a category of the questions and I was wondering whether it is possible to have the answered quiz items be categorized according to the question group?

I want to see the performance of the student on the quiz based on that particular category


Thanks so much!

Labels (1)
2 Solutions
Community Champion


Since you mention question groups, I'm going to assume you're talking about Classic Quizzes.

The information about the question group is not included with the analysis export. It will require extra effort on your part.

Here are some things you might be able to do.

  • Manually go through and add the quiz group information to the spreadsheet.
  • Add some text to the question that identifies the group. Then look for that text to appear in the question text of the spreadsheet, perhaps using the FIND() function in Excel.
  • Fetch the question groups from using the Quiz Questions API and then match it based off the question ID, which appears in the spreadsheet. This will work only if you included the questions in the quiz. If the questions are from a question bank and you linked to them, then the API doesn't return the questions.

View solution in original post


Using the API is an advanced technique that typically requires some programming capability. It's too much to fully explain in a single message and there is a Canvas Developers group here in the Community that already has a lot of information in it. If you're going to do this repeatedly, then I would recommend going that route, possibly asking someone at your school for support if you don't have the programming skills for it.

If this is a infrequent, perhaps only once, analysis that you need quickly, then there is another way for this project.

In a browser, go to the quiz you need the results for. If your course ID is 123 and your quiz ID is 456, then your URL will look something like <instance>/courses/123/quizzes/456 where <instance> is the hostname of your Canvas instance.

In the browser's location bar, insert /api/v1 between the instance and the /courses and then add /questions to the end.

It now looks like <instance>/api/v1/courses/123/quizzes/456/questions

That will get you up to 10 questions. If you have more than 10 questions, which is likely at some point, then add ?per_page=100 to the end. That will get you up to 100 questions. At this point, your URL looks like <instance>/api/v1/courses/123/quizzes/456/questions?per_page=100

Making it more than 100 will not give you more than 100 questions, there's a limit of 100. You'll have to mess with pagination if that's the situation, but it basically involves adding &page=2 or &page=3 at the end until you get all of the questions. If you have to mess with pagination, then you'll want to repeat the steps below for each block of questions and then merge them together in Excel.

That will give you some JSON output, which is intended to be computer-friendly rather than human-friendly. It should start and end with a [ and ] which signifies it is an array or list. There is one element in the array for each question on the quiz. 

You can select that output and paste it into an online JSON to CSV converter. There are several available. I have my students use a couple of different ones, but I typically get better results from I tried the output from the quiz questions API at both and it definitely works better with that data. Plus, it has the benefit of doing the entire conversion within the browser so there's no data that escapes in case you're concerned about that.

  1. Paste the input into the box. It's not necessary to click Format JSON, but if you want to see what it looks when formatted, you can do that. You'll see a quiz_group_id and position. Those are the two big things for what you want.
  2. Choose output options. If you choose tab as the output field separator, then you can copy/paste the data into Excel
  3. There are two options here. I recommend the first.
    1. Click Convert JSON to CSV to get a table within the browser. If you picked tab in step 2, then you can copy/paste this into Excel. The tab and copy/paste approach is what I recommend if you already have Excel open. If you leave the output separator as a comma (the default), then scroll down a little to find a table with a Download Result button above it. This generates a CSV file that Excel can open. Note that if you go back to step 2 and change the options, you will need to re-click the Convert JSON to CSV.
    2. There is a JSON to Excel button that sounds enticing. It will generate an Excel file that you can open. As tempting as it sounds to use the JSON to Excel, it generates a file where numbers are stored as text. I had a lot of students have to redo an assignment because they chose JSON to Excel. If you don't care that numbers are stored as text (possibly affecting the sort as 10 comes before 2), go ahead.

Now that you have the data about the questions in Excel, you're looking at the quiz_group_id and potentially the position columns.

The quiz_group_id will be the same for each question within a question group. The position represents the position of the question within the question group _or_ the position of the question within the quiz if there is no question group (standalone questions).

There is an "id" field there, which is the ID of the quiz question because you were using the quiz question API to get the information. That would match up with the first part of the question text in the Excel that Canvas generates. I'm talking about that first row where it has a number, colon, and then the text of the question.


Typically, we do not care about the position of the question within the question group because we are randomizing them when delivered to the student. But if you're editing the quiz questions and trying to find it, then it may be useful. There's also a question_name field available if you use that.

For me, the order of the data matches the order of the question groups within the quiz. All of position=1 questions are listed first, but the order of the qroups matches the order order delivered on the quiz. However, that also happens to be the order of the quiz_group_id values, meaning that the I still had the original order in which I created the question groups.

I went into my beta instance of Canvas and re-arranged the order of the question groups. The results are still in the same order as the original creation (by quiz_group_id) and not the order they are displayed in the quiz. In other words, if you moved question groups around at all, do not assume that the order that they appear on the quiz is the order that they appear in the data. In general, you should assume that any JSON data you get from Canvas is unordered unless there is a sort option.

If you need to find the order of the question groups on the quiz itself, the fastest way is by editing the quiz questions and looking at them. But if you're trying to do it programmatically, then there is a quiz question groups API that allows you to retrieve the position of the group.

You need the quiz_group_id from data to find this. Let's say that one of my groups has an ID of 789. Then my URL would look like <instance>/api/v1//course/123/quizzes/456/groups/789

There is no need to add per_page here as it will only return a single group at a time.

It returns a position, which is the position of the question group within the quiz. Note that this is the question position of the group. When I moved my group, what was position 1 became position 4. Then I went and added a regular (non-group) question before it and the position became 5 because it is now the fifth question.

Note that the question I added did not have a quiz_group_id or a position, it appears in what seems to be a non-sensical location. I put the question in position 3, but it showed up as the next-to-last question in the JSON.

After going bald from scratching your head trying to figure it out, you realize this makes sense. My next-to-last spot in the data was position 3 because of the one group that had 4 items. So Canvas is sorting by position of the question or group, but not showing the position if it's not a group.

And now that I've played around with the order of the questions, my question groups are no longer by ID. But they're not by the order they appear in the quiz, either. That goes back to the "don't assume there is an order in your JSON" statement. However, it does look that Canvas sorts by position, even if the position isn't there. That should be verified by looking at the source code to see if there is a sort involved, but we often take observed data and make an inference about it and it frequently works -- until it doesn't.


I hope that helps. If nothing else, perhaps I've shown why there needs to be an entire group to discuss questions that sound as simple as "how do I use the API to get the groups?"

View solution in original post