Writing a script for Canvas LMS

Jump to solution
shh1cd
Community Explorer

I tried to find a way not to copy and paste Canvas rubrics and find the posting below. 

"I've written an Rubric Importer user script that will allow you to copy a rubric from a spreadsheet like Excel or Google Sheets and paste it into a textbox inside Canvas and then automatically turn it into a rubric within Canvas. Many feature requests have asked for improving the rubric experience and https://community.canvaslms.com/ideas/6311-allow-importing-of-rubrics-from-csv-format  is currently in the Gathering Information stage." 

What kind of a programming language you can use to write this kind of script or customize Canvas? 

2 Solutions
melodyc_lam
Community Contributor

Hi! Basically any programming language that supports HTTP calls will work with interacting with the Canvas API. This is majority (if not all) programming languages.

A lot of Canvas API users use Python to interact with the API. There's a great library (canvasapi) that is open source and maintained by UCF and other users that c...

If you're using Google Sheets, there is a scripting library (Google App Script) that interacts directly with Google documents and also supports external HTTP calls 🙂

Hope this helps!

View solution in original post

James
Community Champion

@shh1cd 

That quote seems a lot like something I wrote. At the time, there was no public API for creating rubrics through the API, it was internal calls within Canvas. That means that I had to use a userscript that ran within the browser to do it. That had the benefit of making it easy for instructors and instructional designers to use it. Since then, Canvas has added an API endpoint to create a rubric, which means that you can certainly do this without the copy/paste.

If I was to write this today, I would still go the copy/paste route for simplicity. The only difference would be that I would use the API calls rather than the internal routes that I used back then.

 

I would not recommend exporting directly from a spreadsheet, although it might make the most sense to someone. That is, we're using a spreadsheet to create the rubric, why not use it to import it into Canvas? The reason is that to import it, you need IDs from Canvas for the course (or account). Those are possible to add to Google Sheets -- I've written several Google Sheets that work with Canvas and there's an interface to prompt for a course ID in some of them. But a person doing this is likely going to be doing it for multiple courses and multiple rubrics and changing that number (or forgetting to change that number) could be painful.

If I wanted to write something for the programmer (as opposed to a non-tech user), then I could create my rubric in a spreadsheet and save it. Then I would write code that would parse the file (CSV or XLSX doesn't really matter), put it into the format specified in that create a rubric endpoint, and send it to Canvas. 

If you are programmatically creating the rubric, you could make it all part of the same program, but if people are manually creating rubrics for you to upload, then I would separate the process of creating the rubric from the process of getting the rubric into Canvas.

As @melodyc_lam wrote, you can use pretty much any modern programming language that you are familiar with.  There are libraries that will handle most of the heavy lifting for you. You just need something that will (1) parse a spreadsheet [if that's the route you're going] and (2) make HTTP requests.

The rest of the logic is all on you. There is code in Canvas to create outcomes from a CSV file, that does not exist for Rubrics. You cannot send a CSV file directly to Canvas. Your code needs to manipulate the rubric into the format needed by the API. It's possible that someone has already written code to send a CSV file to Canvas using an API. It sounds familiar, I just cannot remember where I might have seen it.

 

View solution in original post