A talk from the Washington Canvas User Group 2014 meeting, about using PHP to automate tasks using the Canvas LMS API. Sample code is available at https://github.com/drlippman/canvas-scripts
2. Outline
Quick overview of the Canvas API
Why would we want to use it?
Examples of scripting against the API
Examples of scripting against export files
3. API
API = Application Programming Interface
A way for other programs to access data or
make changes in Canvas courses
https://canvas.instructure.com/doc/api/
12. Use Case 1: Adding Attribution
Course with 100+ text pages
All needed a Creative Commons attribution
statement added
Option 1: Edit each by hand
Option 2: Modify an export file
Option 3: Use the API!
13. The General Idea
Call the page list.
https://domain.instructure.com/api/v1/courses/12345/pages
14. The General Idea
Call the page list. Repeat if needed.
$endpoint = /api/v1/courses/$courseid/pages/;
$itemlist = json_decode(
file_get_contents(
https://.$domain.$endpoint.
?per_page=50&page=.$pagecnt.
&access_token=.$token
));
foreach ($itemlist as $item) {
$url = $item->url;
26. Working with Exports
Upsides:
Can be faster for large numbers of pages
Can look at changes before uploading
Downsides
Cant be done on a live class
Have to make sense of the file format
27. Working with Exports
Canvas exports are based on Common
Cartridge
Exports are renamed zip files
Exports contain XML, HTML, and files
Main file is imsmanifest.xml
<resource> shows type and location of items
<item> shows item structure (modules)