Your Community is getting an upgrade!
Read about our partnership with Higher Logic and how we will build the next generation of the Instructure Community.
Found this content helpful? Log in or sign up to leave a like!
I've just begun playing with api's and powershell and I think I've managed to wrap my head around the basics. I'm just really stuck with the pagination of canvas. I can pull 50 submissions from a course and filter out all bar the passes - which is what I'm interested in. But I can't get it to wrap to the next page, I think it's going to be using the while function but I don't know what to put in it as the condition or the statement. Does anyone have any idea what I need to add to it?
This is what I have so far:
$headers = @{"Authorization"="Bearer "+$token}
$uri = “https://bfc.instructure.com/api/v1/”
$my_page = ((Invoke-WebRequest -headers $headers -uri "$uri/courses/547/students/submissions?student_ids[]=all&workflow_state=graded&sort=id&per_page=50.json").content | convertfrom-json) | Where-Object -property grade -eq "Pass"
$my_page | Select-Object -property id, grade, user_id, assignment_id
I'm also aware this may not be the best approach to grab a list of all users and grades on a course - if not what way should I approach it?
I've done some more hunting this morning and found this which will probably give me the data in an easier to parse manner Analytics - Canvas LMS REST API Documentation but for the loop I'd have to have it change the student_id every time. Does anyone know what bit of code I need to achieve that?
I would use PowerShell 7 with the Invoke-RestMethod cmdlet . It has a parameter that automatically handles pagination. For example, Invoke-RestMethod -FollowRelLink 50. This makes it really easy to make API calls that have multiple pages of data. The 50 references the number of next rel pages the command will attempt to go to until it stops. The previous results will be stored in an array if you use a variable to make the API call. This can then be sorted or exported.
Oooh I'll give that a go. I'm still very new to powershell so just figuring out the different cmdlets.
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