Canvas API
2024-Mar-17, Sunday 05:05 pmI've mentioned before that I can feel my brain starting to think again, thanks to an extended reprieve from the very busy months before now. As further evidence of this improvement, I spent my spare time between tickets today actually learning something!
Many places use Canvas as their educational platform. Both Penn State and the University of Minnesota do, for example. Today, I learned how to use PowerShell to pull information from the Canvas platform. It was surprisingly easy, after I figured out that they provided very easy access to the text token you use to interact with their servers. They provide API access to all students, for example.
After I manually generated my token, it was easy to insert "api/v1/" into the url that I would normally use at the webpage for their gui platform, then use my script instead. The Course ID is just the part of the url that shows whenever you access that class through the webpage (and not the SIS ID as I first assumed). Here's a sample of the short code, with a few key text strings redacted for security safety.
$headers = @{ Authorization='Bearer [redacted]} $idCourse1 = '[redacted]' $uri=”https://[redacted].instructure.com/api/v1/courses/$idCourse1/discussion_topics" $response = Invoke-RestMethod -Method 'Get' -URI $uri -Headers $headers -ContentType application/json $response | Select-Object posted_at, title, message | Out-GridView
And that brief code showed me a list of all the Discussions in my course sandbox.
It's nice to be able to think again.