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

Canvas Quiz Submission API does not return all submissions

Jump to solution

Hi I am new to Canvas API usage.

I am trying to write a script using PowerShell that needs to grab all submissions data of a particular quiz in a section (Submission Time, Kept Score, User ID etc). I am using the following API call:

$url = "https://$domain/api/v1/courses/<course #>/quizzes/<quiz #>/submissions?include[]=user"

using the following invoke-webrequest block:

$quizObject = Invoke-WebRequest -Headers $headers -Method Get -Uri $url |
convertfrom-json |
select -expand quiz_submissions |
select user_id, finished_at, kept_score | export-csv -path quizObjectOutput.csv -NoTypeInformation

I am able to get data back, use the JSON data etc and get my script to do everything I needed to do.

The issue is, I am only getting partial data back, exactly 10 submissions. I exported the grade book via GUI and can see I there are roughly 50 submissions for the quiz. Is there any API limitation that I am not aware of? Why I am not getting all 50 submissions?

any help is appreciated!! I have hit the brick wall with this!!

Update: 

I found this - which seems to answer why I am getting only 10 results because responses are paginated.

https://community.canvaslms.com/t5/Question-Forum/get-all-quiz-submissions/m-p/421241/highlight/true...

what it does not tell me is How do I know how many pages I have beforehand? 
How am I supposed to loop through the pages if I don't know how many pages are out there?

Labels (1)
0 Kudos
1 Solution

Accepted Solutions

hmm I'm not familiar with Powershell. I found this, don't know if it is helpful? Screenshot 2021-01-14 at 16.10.31.png

View solution in original post

8 Replies
mrahman_bcc
Community Participant

I found this - which seems to answer why I am getting only 10 results because responses are paginated.

https://community.canvaslms.com/t5/Question-Forum/get-all-quiz-submissions/m-p/421241/highlight/true...

what it does not tell me is How do I know how many pages I have beforehand?

werner_huysman1
Community Participant

Hi,

you would have to loop and use the Link headers, as explained here: https://canvas.instructure.com/doc/api/file.pagination.html. The 'last' will tell you the number of pages.

Thanks so much for your response, Werner.

I was able to write my code in a not-so-standard way to get the pagination handled - so for now I am ok

However, I am curious to learn to do it the proper way. I am still not understanding how the header links should be used.

My URL is:
$url = "https://$domain/api/v1/courses/course #/quizzes/quiz #/submissions?include[]=user&page=$pagevalue"

I invoke the URL with this:
$quizObject = Invoke-WebRequest -Headers $headers -Method Get -Uri $url 

and my header variable is:
$headers = @{"Authorization"="Bearer "+$token}

When I examine the response I am getting back, I do not see anything related to Link Header that I can use. Is that because I need to specify something else in my $headers in addition to the token authorization?

 

Which technology do you use?

mrahman_bcc
Community Participant

I am using MS Powershell.

hmm I'm not familiar with Powershell. I found this, don't know if it is helpful? Screenshot 2021-01-14 at 16.10.31.png

View solution in original post

This is what I get from a simple test in Postman using the list assignments endpoint:
Screenshot 2021-01-14 at 17.22.28.png

That is a good find Werner!

My testing looks promising with that approach and I will put it to use after further testing!

Thanks so much for your help!!