Canvas and Mastery are experiencing issues due to an ongoing AWS incident. Follow the status at AWS Health Dashboard and Instructure Status Page
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.
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?
Solved! Go to Solution.
hmm I'm not familiar with Powershell. I found this, don't know if it is helpful?
I found this - which seems to answer why I am getting only 10 results because responses are paginated.
what it does not tell me is How do I know how many pages I have beforehand?
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?
I am using MS Powershell.
hmm I'm not familiar with Powershell. I found this, don't know if it is helpful?
This is what I get from a simple test in Postman using the list assignments endpoint:
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!!
To interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in
This discussion post is outdated and has been archived. Please use the Community question forums and official documentation for the most current and accurate information.