Canvas API

2024-Mar-17, Sunday 05:05 pm
mellowtigger: (penguin coder)
[personal profile] mellowtigger

I'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.

Profile

mellowtigger: (Default)
mellowtigger

About

August 2025

S M T W T F S
      12
34567 8 9
10 111213141516
1718 1920212223
242526 2728 2930
31      

Most Popular Tags

Powered by Dreamwidth Studios
Page generated 2025-Sep-01, Monday 04:18 am