[ARCHIVED] Individual Quiz Answers - Canvas API

Jump to solution
afuenmayor
Community Explorer

Our campus is trying to compile quiz response data for our annual review process. In trying to compile this data I came across this API call which gives me all the data I need for a given quiz:

https://institution.instructure.com:443/api/v1/courses/<course_id>/assignments/<assignment_id>/submi...

This call displays quiz_id, user_id, question_id, answer_id, and whether or not that answer was correct for every student who took the quiz and every question they answered.

To extract this data systematically across a large number of quizzes we created a short python script using the canvasapi library. However, we are having trouble getting the answers students gave to individual questions. It appears as though in the submission_questions endpoint the individual answer data does not exist as described in this github thread. That thread is now five years old though so I was wondering if anyone has found another solution

Labels (2)
0 Likes
1 Solution
mboldin
Community Member

You can try a requests based extract.  The code below worked for me

Just substitute in your URL, KEY and the ID numbers

Not as easy as using the python canvasapi module, but the data comes in as a python dictionary nonetheless
import os
import requests
import json

URL1 = r'https://XXXXXXX.instructure.com/api/v1/courses'
course_id = 99999
assignment_id = 99999

url2 = f'{URL1}/{course_id}/assignments/{assignment_id}/submissions?include[]=submission_history'
                                                                                                   
header = {'Authorization': 'Bearer ' + '%s' % KEY}
r = requests.get(url2, headers= header)
print('Request status code',r.status_code)
a = r.json()
for x in a:
    print(x['id'],x['user_id'])
    print(x['submission_history'])

View solution in original post