How to get a history of all reports of a quiz

Jump to solution
fabiocunha
Community Explorer

Hi,

I have a quiz that allows students to write their answers on it.

Now, I want to get all those answers using the API.

I generate a report using the command below:

print ( "curso: "+str(course.id)+" - quiz: "+str(quiz.id) )
        headers = {'Content-Type''application/json','Authorization''Bearer {}'.format(API_KEY)}
        url = API_URL+'/api/v1/courses/'+str(course.id)+'/quizzes/'+str(quiz.id)+'/reports?quiz_report[report_type]=student_analysis&quiz_report[includes_all_versions]=1'.format(course.id, quiz.id)
        response = requests.post(url, headers=headers)
        r = json.loads(response.content.decode('utf-8'))
        url2 = r.get('url')
        print('URL Atualizado:', url2, sep = '\t')

This generates the report for me.

After that, I use the following URL to get the report

https://mycompany.instructure.com/api/v1/courses/:course_id/quizzes/:quiz_id/reports/?includes_all_v...

I get the following answer:

https://www.npoint.io/docs/4c28ce994cd95ac7b8e4  ( please click to see the JSON answer)

In the JSON answer, it got a parameter file, inside the file parameter, there is a URL parameter, I use this parameter to download to extract the CSV file and read the results from it.

But on the next day, I try to get CSV again, but I got an answer like this:

https://www.npoint.io/docs/6b8e4da433d1a024240a ( please click to see the JSON answer)

There are other students reports that are generated that overwrite the most recent response?

Is it possible to get only the most recent report that contains the file['url'] parameter?

 

0 Likes
1 Solution
fabiocunha
Community Explorer

I didn't add the parameter include[file] to the query, I think it was not supposed to store this value.

I take a different approach now and I was able to solve my problem now.

In the title, I write that I want all history of reports, but what I need its just the last report for a quiz with a specific title.

I need the CSV file from this last report, I need the URL where the CSV is stored.

I just make a request for this URL:

https://mycompany.instructure.com/api/v1/courses/:course_id/quizzes/:quiz_id/reports?quiz_report[rep...

This URL generates the report for me, but it needs some seconds to create the report. So, I just wait for 10 seconds and send a new request to the same URL, this time I got the CSV URL. 

The job is done. I use the CSV to show a detailed report for that course on my custom web page.

View solution in original post

0 Likes