cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
fabiocunha
Community Participant

How get all answers from a quiz using the API

I use the endpoint below to get all submissions from a specific course

https://myconpany.instructure.com/api/v1/courses/:course_id/quizzes/:quiz_id/submissions 

For each answer, I have a html_url, for example

https://mycompany.instructure.com/courses/8718/quizzes/58321/submissions/1409414 

that is converted to 

https://mycompany.instructure.com/courses/8718/quizzes/58321/history?user_id=3341 

I was able to see the user_id by the URL and all answers from that user on the HTML page.

Is there an API endpoint that I was able to see the answers from the student(including the answer that students write).

Labels (1)
Tags (1)
6 Replies
James
Community Champion

 @fabiocunha  

There is an documented switch that has the undocumented side effect of giving you the quiz responses.

Get the submissions (not quiz submissions) for the corresponding assignment and be sure to add the query parameter: include[]=submission_history.

Let's say that I have a quiz at /courses/896851/quizzes/3986251. If I GET /api/v1/courses/896851/quizzes/3986251, I see that the assignment_id is 13300109.

Then I GET /api/v1/courses/896851/assignments/13300109/submissions?include[]=submission_history.

It returns an array of users, and each user that has taken the quiz has a submission_history.submission_data array. That array contains an object for each question.

Here is an example (just the submission_data portion) from a quiz I gave.

{
"submission_data":[
{
"correct":true,
"points":1,
"question_id":73065717,
"answer_id":5521,
"text":"5521",
"more_comments":""
},
{
"correct":"defined",
"points":0,
"question_id":73065719,
"text":"<p>An ancient Egyptian casket.</p>",
"more_comments":""
}
]
}

The response to the essay question (question 2) was "An ancient Egyptian casket."

To make sense out of the first question, you need to get the information about the question from somewhere else.


I can do that with GET /api/v1/courses/896851/quizzes/3986251/questions

The first question had question_id=73065717 and was "What is the teacher's favorite color?". From the answers object, you can tell what response 5521 is. Do NOT look at the text property here, they didn't type 5521.

For the second question, id=73065719, the question_type was "essay_question" and the text was "Explain sarcasm." The text in this case is what the student typed.

See the appendix of question answer formats at the bottom of the Quiz Submission Questions API documentation for additional information.

fabiocunha
Community Participant

Thanks for the help, but I think this approach will not work for me.
I check my quiz id using the endpoint
On the quiz that I want the answers, the "assignment_id" is null. So, because of that, I can't use the endpoint below
Is there another way to get those answers?

Hi  @fabiocunha ,

Did you tried to get all submissions for all assignments? And after that search for your quiz_id?

I had a similar issue in the past and  @jamesjonespa ‌ kindly helped me with excellent explanations on that post: https://community.canvaslms.com/thread/44434-is-there-an-api-call-that-get-a-list-of-all-submissions... 

Hope it helps!

James
Community Champion

Is your quiz a practice quiz or ungraded survey? They may not have assignments associated with them. One thing you could do (untested) is to go to your beta instance, change it to be a graded assignment, and then get the results out of it as I described earlier.

Quizzes that don't have an associated gradebook entry will not return an assignment_id. I would assume there is no way to get submission_history for them. 

nm8
Community Member

Hi James, I tried this but it didn't work. Can you verify that it's still working on your end? I am not seeing the submission_data portion in the response