cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cayala
Community Member

Exporting Quiz Submissions

Jump to solution

Is there any way to export quiz submissions, including all of the responses given by a student? I see that there is a way to export quiz content, but that exports the quiz itself. What I am looking to do is download (either through the website, or preferably through the Canvas API) the actual responses given by a student. We plan to use Canvas to host the quiz, then process the response data elsewhere.

Tags (1)
1 Solution

Accepted Solutions
James
Community Champion

Deactivated user​,

This is a follow-up to my previous post where I said it can't be done through the API because the quiz submissions API is broken. I went back and re-read Kona's message and saw that she had mentioned the reports. That sparked an idea and it turns out that there an API for the reports (I've just never used it), so if you're okay with that, you might try it. Personally, I think the CSV files aren't particularly well laid out, but it will have the most of the information about the student responses, although you'll definitely have fun parsing it. I downloaded it for a quiz that had a huge question pool to choose from and it ended up taking me out to column AEA (807) in Excel with a very sparse table.

You will need to download the Quiz questions to make any real sense out of it, although the text of the question is there, you may not know where that question belongs if it's in a pool or bank.

See the Quiz Reports API for more information. It's the student_analysis that you're after.

Anyway, to get the report through the API, here's what you do:

Create a Report with a form payload of query_report[report_type]=student_analysis

Wait a little bit (usually 10 seconds is enough, but it depends on the complexity of the quiz and the number of students taking it) and Get the list of reports to check and see if the report is done. There will be a file property in the JSON returned when it is ready. If not, you wait and then try again. Or you just schedule it and then come back at another time to download them.

When it is finished, there will be a "file" entry in the results. This will have an "url" which contains an URL that you will need to get to retrieve the file. Do not use the URL unless it's inside the file section.

This is just a regular GET and you should not add the Authorization header to it. If you do, it will send redirects, which your REST client may not be able to handle. When I tried it with Chrome's Advanced REST Client, I ended up with a 400 Bad Request. The URL contains a verifier code on it that bypasses the normal authentication required and it's not an API call, so just leave off the Authorization when you download the CSV file and all will be well.

Sorry for the confusion earlier, I thought Kona was trying to get met to explain the way I had done it before. I did test this method and it works, I just had never used it before.

View solution in original post

3 Replies
kona
Community Coach
Community Coach

Deactivated user​, you can download quiz answers directly from the quiz using these steps: click on your quiz --> Quiz Statistics --> Student Analysis. Yet, I also know you can get this via the API, I'm just not sure what you use to call this information. Our back end Canvas guru has done this a number of times so I'll check with him and get back to you.

James
Community Champion

 @kona ​ overstated what I had accomplished.

I started doing something along those lines at Hack Night at InstructureCon2014. I wanted a way to regrade multiple answer questions based on different approaches than what Canvas does with it's weird way that no students understand, not unlike the feature request (except that wasn't a particular method I was going to consider, but things like that).

I got as far as realizing that Canvas would only return the latest attempt and for me that was a deal breaker since I allow multiple attempts on quizzes and the last one may not be the best one. It might have been okay for faculty who only allow one attempt. So I quit working on it and as far as that portion of the code had gotten was a note to add that function to the API routines.

Since my code was unfinished, I had to do some testing to answer your question.

The short answer is that you want Get All Quiz Submission Questions, but that the API is broke (it doesn't deliver what it says it does) and this returns the list of questions but not the list of answers, which is what the documentation says. In fairness, it says the API may change, but the documentation is supposed to keep up with it, so you might want to file it as a bug report.

I'm going to ahead and leave the rest of the message I had typed up before I realized that it was broke. In case Canvas gets it fixed, it may prove beneficial to someone.

But for now, I can't find a way to get it out of the API.

That said, there is a way to view it from within Canvas, so you may have to scrape the web pages for the information provided until Canvas can get the API fixed (if they're even aware it's broken). When you get the list of quiz submissions, there is an html_url field that matches the API call but without the /api/v1 in there.  For example: https://<canvas>/api/v1/courses/12345/quizzes/6789/submissions/99999​ returns statistics about the submission, including the score, time, when started, etc. But https://<canvas>/courses/12345/quizzes/6789/submissions/99999​ returns the HTML page of the quiz itself.

Sorry I can't be as much help as Kona thought I could.

Here's what I had written.

For purposes of the example, let's say the URL in Canvas for the quiz (from somewhere like the Moderate page) is /courses/12345/quizzes/6789

Step 1: Get a List of Quiz Submissions

The first step is to get a list of Quiz submissions via the Quiz Submissions API​.

In particular, you are looking for the "Get All Quiz Submissions" which has an endpoint of GET /api/v1/courses/:course_id/quizzes/:quiz_id/submissions

You want to make sure you include the submission. For the example above, I would use

GET /api/v1/courses/12345/quizzes/6789/submissions?include[]=submissions

There will be an object quiz_submissions, which is an array containing an entry for each student who has taken the quiz. In particular, you'll want to note the id even though there is a field called submission_id. It is the id and not the submission_id that is needed in the next step.

For illustration purposes, let's say one of the students has an id = 99999 and a submission_id = 77777. You want the id = 99999 for the next step.

.

You can iterate through this array and perform the next steps for each student.

Step 2: Get Quiz Submissions

Now that you have the id from the of Quiz Submissions, it's time to get the answers the student gave for that submission.

This is done using the Quiz Submission Questions API.

In particular, you are wanting the "Get all quiz submission questions" endpoint of GET /api/v1/quiz_submissions/:quiz_submission_id/questions

The :quiz_submission_id is the id found step 1.

GET /api/v1/quiz_submissions/99999/questions

This is also where things break down. It's supposed to give you the answer you want, but it doesn't right now.

Both of those API sections are marked with "BETA: This API endpoint is not finalized, and there could be breaking changes before its final release." But the documentation is supposed to match the code, so I would consider it a bug.

The description of what is supposed to be returned and what are returned are different. What is happening is that it is returning a list of the questions, which is only supposed to happen if you include[]=quiz_question in the call.

It is not returning the actual answers that were given by the student.

James
Community Champion

Deactivated user​,

This is a follow-up to my previous post where I said it can't be done through the API because the quiz submissions API is broken. I went back and re-read Kona's message and saw that she had mentioned the reports. That sparked an idea and it turns out that there an API for the reports (I've just never used it), so if you're okay with that, you might try it. Personally, I think the CSV files aren't particularly well laid out, but it will have the most of the information about the student responses, although you'll definitely have fun parsing it. I downloaded it for a quiz that had a huge question pool to choose from and it ended up taking me out to column AEA (807) in Excel with a very sparse table.

You will need to download the Quiz questions to make any real sense out of it, although the text of the question is there, you may not know where that question belongs if it's in a pool or bank.

See the Quiz Reports API for more information. It's the student_analysis that you're after.

Anyway, to get the report through the API, here's what you do:

Create a Report with a form payload of query_report[report_type]=student_analysis

Wait a little bit (usually 10 seconds is enough, but it depends on the complexity of the quiz and the number of students taking it) and Get the list of reports to check and see if the report is done. There will be a file property in the JSON returned when it is ready. If not, you wait and then try again. Or you just schedule it and then come back at another time to download them.

When it is finished, there will be a "file" entry in the results. This will have an "url" which contains an URL that you will need to get to retrieve the file. Do not use the URL unless it's inside the file section.

This is just a regular GET and you should not add the Authorization header to it. If you do, it will send redirects, which your REST client may not be able to handle. When I tried it with Chrome's Advanced REST Client, I ended up with a 400 Bad Request. The URL contains a verifier code on it that bypasses the normal authentication required and it's not an API call, so just leave off the Authorization when you download the CSV file and all will be well.

Sorry for the confusion earlier, I thought Kona was trying to get met to explain the way I had done it before. I did test this method and it works, I just had never used it before.

View solution in original post