SlideShare a Scribd company logo
1 of 31
Automation using Scripting
and the Canvas API
David Lippman
Pierce College
Lumen Learning
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
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/
API
“REST”: Basic GET/PUT/POST HTTP calls
JSON format return
https://domain.instructure.com/api/v1/courses
Authentication
HTTP Authorization Header
Send access token in the query string
https://domain.instructure.com/api/v1/courses?access_token=<ACCESS-TOKEN>
Generating a Token
Generating a Token
Scroll down…
Generating a Token
Generating a Token
So where does that get us?
or
Why should we care?
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!
The General Idea
Call the page list.
https://domain.instructure.com/api/v1/courses/12345/pages
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;
The General Idea
Grab the wiki page body.
The General Idea
Grab the wiki page body. Add attribution.
$endpoint = “/api/v1/courses/$courseid/pages/$url”;
$page = json_decode(
file_get_contents(
„https://‟.$domain.$endpoint.
„?access_token='.$token
));
$html = $page->body;
$html .= $attribution;
The General Idea
Send back
The General Idea
Send back using CURL
$endpoint = “/api/v1/courses/$courseid/pages/$url”;
$ch = curl_init(„https://‟.$domain.$endpoint.
„?access_token=‟.$token );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS,
„wiki_page[body]=‟.urlencode($html));
$response = curl_exec($ch);
Time to Library-ize
require("canvaslib.php");
$api = new CanvasLMS($token,$domain);
$pages = $api->getPageList($courseid);
foreach ($pages as $id=>$name) {
$body = $api->getPageData($courseid, $id, 'body');
$body .= $attribution;
$api->updatePage($courseid, $id,
array("body"=>$body));
}
Use Case 2: Assignment Settings
Adding Instructions to all Assignments in a course
Use Case 2: Assignment Settings
$assn = $api->getAssignmentList($courseid);
foreach ($assn as $id=>$name) {
$api->updateAssignment($courseid, $id,
array(“description”=>$text));
}
Use Case 3: Fixing links
foreach ($pages as $id=>$name) {
$body = $api->getPageData($courseid, $id, 'body');
$body = str_replace(“oldsite.com”,“newsite.com”,
$body);
$api->updatePage($courseid, $id,
array("body"=>$body));
}
Use Case 4: Removing Links
foreach ($pages as $id=>$name) {
$body = $api->getPageData($courseid, $id, 'body');
$body = preg_replace(
'/<a[^>]*badsite[^>]*>(.*?)</a>/sm',
' $1 ', $body);
$api->updatePage($courseid, $id,
array("body"=>$body));
}
Use Case 5: Rehosting Images
preg_match_all(
„/images.badsite.com[^>]*(gif|png|jpg)/„,
$str, $matches);
foreach ($matches[0] as $m) {
$bn = basename($m);
cp(„http://‟.$m, ‟./imgs/‟.$bn);
$str = str_replace($m, „newhost.com/‟.$bn, $str);
}
General purpose, web-based tool
Append
Replace
Search-and-replace
Regex search-and-replace
http://www.imathas.com/canvas/canvassearch.html
Alternate Approach
Working with Exports
Upsides:
• Can be faster for large numbers of pages
• Can look at changes before uploading
Downsides
• Can’t be done on a live class
• Have to make sense of the file format
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)
require("phpQuery-onefile.php");
$zip = new ZipArchive;
$zip->open($file);
phpQuery::newDocumentXML(
$zip->getFromName("imsmanifest.xml"));
$ref = pq("resource");
foreach ($ref as $r) {
$reflist[pq($r)->attr("identifier")] =
pq($r)->attr("href");
$reftype[pq($r)->attr("identifier")] =
pq($r)->attr("type");
}
$items = pq(“item”);
foreach ($items as $item) {
$iref = pq($item)->attr("identifierref");
if (isset($reftype[$iref]) &&
$reftype[$iref]=="webcontent") {
$filename = $reflist[$iref]);
$html = $zip->getFromName($filename);
$html = str_replace(„</body>‟,
$attribution.‟</body>‟, $html);
$zip->addFromString($filename, $html);
}
}
Sample Code
https://github.com/drlippman/canvas-scripts
• A simple library for doing API calls
• A sample program using the library
• The web-based general purpose tool
• Search-and-replace in a cartridge example

More Related Content

What's hot

Οδηγός Χρήσης Dropbox για εκπαιδευτικούς
Οδηγός Χρήσης Dropbox για εκπαιδευτικούςΟδηγός Χρήσης Dropbox για εκπαιδευτικούς
Οδηγός Χρήσης Dropbox για εκπαιδευτικούςNikos Kaklamanos
 
Ερωτήσεις χορήγησης πιστοποιητικού γνώσεων ορθολογικής χρήσης γεωργικών φαρ...
 Ερωτήσεις χορήγησης πιστοποιητικού γνώσεων  ορθολογικής χρήσης γεωργικών φαρ... Ερωτήσεις χορήγησης πιστοποιητικού γνώσεων  ορθολογικής χρήσης γεωργικών φαρ...
Ερωτήσεις χορήγησης πιστοποιητικού γνώσεων ορθολογικής χρήσης γεωργικών φαρ...Ελληνική Γεωργία
 
ELKOMP 2019: Beredskapsforskriften, ny oppdatering med veiledning - Helge Uls...
ELKOMP 2019: Beredskapsforskriften, ny oppdatering med veiledning - Helge Uls...ELKOMP 2019: Beredskapsforskriften, ny oppdatering med veiledning - Helge Uls...
ELKOMP 2019: Beredskapsforskriften, ny oppdatering med veiledning - Helge Uls...Trainor Elsikkerhet AS
 
Tα δομικά μέρη του δικτύου υπολογιστών
Tα δομικά μέρη του δικτύου υπολογιστώνTα δομικά μέρη του δικτύου υπολογιστών
Tα δομικά μέρη του δικτύου υπολογιστώνbasflor
 
ΤΑΞΙΔΙ ΣΤΟ ΥΠΟΛΟΓΙΣΤΙΚΟ ΝΕΦΟΣ
ΤΑΞΙΔΙ ΣΤΟ ΥΠΟΛΟΓΙΣΤΙΚΟ ΝΕΦΟΣ ΤΑΞΙΔΙ ΣΤΟ ΥΠΟΛΟΓΙΣΤΙΚΟ ΝΕΦΟΣ
ΤΑΞΙΔΙ ΣΤΟ ΥΠΟΛΟΓΙΣΤΙΚΟ ΝΕΦΟΣ 1lykspartis
 
Πρωτόκολλα και Αρχιτεκτονική δικτύου, το μοντέλο OSI
Πρωτόκολλα και Αρχιτεκτονική δικτύου, το μοντέλο OSIΠρωτόκολλα και Αρχιτεκτονική δικτύου, το μοντέλο OSI
Πρωτόκολλα και Αρχιτεκτονική δικτύου, το μοντέλο OSIΙωάννου Γιαννάκης
 
Microsoft Access Θεωρία 1/6
Microsoft Access Θεωρία 1/6Microsoft Access Θεωρία 1/6
Microsoft Access Θεωρία 1/6Michael Ntallas
 

What's hot (8)

Οδηγός Χρήσης Dropbox για εκπαιδευτικούς
Οδηγός Χρήσης Dropbox για εκπαιδευτικούςΟδηγός Χρήσης Dropbox για εκπαιδευτικούς
Οδηγός Χρήσης Dropbox για εκπαιδευτικούς
 
Εφαρμογές νέφους (cloud computing)
Εφαρμογές νέφους (cloud computing)Εφαρμογές νέφους (cloud computing)
Εφαρμογές νέφους (cloud computing)
 
Ερωτήσεις χορήγησης πιστοποιητικού γνώσεων ορθολογικής χρήσης γεωργικών φαρ...
 Ερωτήσεις χορήγησης πιστοποιητικού γνώσεων  ορθολογικής χρήσης γεωργικών φαρ... Ερωτήσεις χορήγησης πιστοποιητικού γνώσεων  ορθολογικής χρήσης γεωργικών φαρ...
Ερωτήσεις χορήγησης πιστοποιητικού γνώσεων ορθολογικής χρήσης γεωργικών φαρ...
 
ELKOMP 2019: Beredskapsforskriften, ny oppdatering med veiledning - Helge Uls...
ELKOMP 2019: Beredskapsforskriften, ny oppdatering med veiledning - Helge Uls...ELKOMP 2019: Beredskapsforskriften, ny oppdatering med veiledning - Helge Uls...
ELKOMP 2019: Beredskapsforskriften, ny oppdatering med veiledning - Helge Uls...
 
Tα δομικά μέρη του δικτύου υπολογιστών
Tα δομικά μέρη του δικτύου υπολογιστώνTα δομικά μέρη του δικτύου υπολογιστών
Tα δομικά μέρη του δικτύου υπολογιστών
 
ΤΑΞΙΔΙ ΣΤΟ ΥΠΟΛΟΓΙΣΤΙΚΟ ΝΕΦΟΣ
ΤΑΞΙΔΙ ΣΤΟ ΥΠΟΛΟΓΙΣΤΙΚΟ ΝΕΦΟΣ ΤΑΞΙΔΙ ΣΤΟ ΥΠΟΛΟΓΙΣΤΙΚΟ ΝΕΦΟΣ
ΤΑΞΙΔΙ ΣΤΟ ΥΠΟΛΟΓΙΣΤΙΚΟ ΝΕΦΟΣ
 
Πρωτόκολλα και Αρχιτεκτονική δικτύου, το μοντέλο OSI
Πρωτόκολλα και Αρχιτεκτονική δικτύου, το μοντέλο OSIΠρωτόκολλα και Αρχιτεκτονική δικτύου, το μοντέλο OSI
Πρωτόκολλα και Αρχιτεκτονική δικτύου, το μοντέλο OSI
 
Microsoft Access Θεωρία 1/6
Microsoft Access Θεωρία 1/6Microsoft Access Θεωρία 1/6
Microsoft Access Θεωρία 1/6
 

Viewers also liked

Automating Canvas Applications Using Selenium
Automating Canvas Applications Using SeleniumAutomating Canvas Applications Using Selenium
Automating Canvas Applications Using Seleniumdavehunt82
 
Html5 canvas + sikuli + selenium 2 web driver
Html5 canvas + sikuli + selenium 2 web driverHtml5 canvas + sikuli + selenium 2 web driver
Html5 canvas + sikuli + selenium 2 web driverISsoft
 
Automating Canvas: difficult but possible
Automating Canvas: difficult but possibleAutomating Canvas: difficult but possible
Automating Canvas: difficult but possibleCOMAQA.BY
 
Test Automation Canvas - не наступайте на глабли автоматизации
Test Automation Canvas - не наступайте на глабли автоматизацииTest Automation Canvas - не наступайте на глабли автоматизации
Test Automation Canvas - не наступайте на глабли автоматизацииAndrey Rebrov
 
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...Yusuke Yamamoto
 
Wso2 con raspberry-pi-cluster
Wso2 con raspberry-pi-clusterWso2 con raspberry-pi-cluster
Wso2 con raspberry-pi-clusterAfkham Azeez
 
Out of box page object design pattern, java
Out of box page object design pattern, javaOut of box page object design pattern, java
Out of box page object design pattern, javaCOMAQA.BY
 
5W2H (метод “7 вопросов”)
5W2H (метод “7 вопросов”)5W2H (метод “7 вопросов”)
5W2H (метод “7 вопросов”)SixSigmaOnline
 
QA Fest 2015. Артем Быковец. Техники тест дизайна или как правильно покрывать...
QA Fest 2015. Артем Быковец. Техники тест дизайна или как правильно покрывать...QA Fest 2015. Артем Быковец. Техники тест дизайна или как правильно покрывать...
QA Fest 2015. Артем Быковец. Техники тест дизайна или как правильно покрывать...QAFest
 
Артём Быковец "Bus Factor - или как контролировать и снижать процессные риски...
Артём Быковец "Bus Factor - или как контролировать и снижать процессные риски...Артём Быковец "Bus Factor - или как контролировать и снижать процессные риски...
Артём Быковец "Bus Factor - или как контролировать и снижать процессные риски...Fwdays
 
WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...
WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...
WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...WSO2
 
Roman iovlev battle - JDI vs Selenide - Selenium Camp
Roman iovlev battle - JDI vs Selenide - Selenium CampRoman iovlev battle - JDI vs Selenide - Selenium Camp
Roman iovlev battle - JDI vs Selenide - Selenium CampРоман Иовлев
 

Viewers also liked (13)

Automating Canvas Applications Using Selenium
Automating Canvas Applications Using SeleniumAutomating Canvas Applications Using Selenium
Automating Canvas Applications Using Selenium
 
Html5 canvas + sikuli + selenium 2 web driver
Html5 canvas + sikuli + selenium 2 web driverHtml5 canvas + sikuli + selenium 2 web driver
Html5 canvas + sikuli + selenium 2 web driver
 
Automating Canvas: difficult but possible
Automating Canvas: difficult but possibleAutomating Canvas: difficult but possible
Automating Canvas: difficult but possible
 
Test Automation Canvas - не наступайте на глабли автоматизации
Test Automation Canvas - не наступайте на глабли автоматизацииTest Automation Canvas - не наступайте на глабли автоматизации
Test Automation Canvas - не наступайте на глабли автоматизации
 
Бизнес кейс
Бизнес кейсБизнес кейс
Бизнес кейс
 
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
JavaOne2016 #CON5929 Time-Saving Tips and Tricks for Building Quality Java Ap...
 
Wso2 con raspberry-pi-cluster
Wso2 con raspberry-pi-clusterWso2 con raspberry-pi-cluster
Wso2 con raspberry-pi-cluster
 
Out of box page object design pattern, java
Out of box page object design pattern, javaOut of box page object design pattern, java
Out of box page object design pattern, java
 
5W2H (метод “7 вопросов”)
5W2H (метод “7 вопросов”)5W2H (метод “7 вопросов”)
5W2H (метод “7 вопросов”)
 
QA Fest 2015. Артем Быковец. Техники тест дизайна или как правильно покрывать...
QA Fest 2015. Артем Быковец. Техники тест дизайна или как правильно покрывать...QA Fest 2015. Артем Быковец. Техники тест дизайна или как правильно покрывать...
QA Fest 2015. Артем Быковец. Техники тест дизайна или как правильно покрывать...
 
Артём Быковец "Bus Factor - или как контролировать и снижать процессные риски...
Артём Быковец "Bus Factor - или как контролировать и снижать процессные риски...Артём Быковец "Bus Factor - или как контролировать и снижать процессные риски...
Артём Быковец "Bus Factor - или как контролировать и снижать процессные риски...
 
WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...
WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...
WSO2Con USA 2017: Iterative Architecture: A Pragmatic Approach to Digital Tra...
 
Roman iovlev battle - JDI vs Selenide - Selenium Camp
Roman iovlev battle - JDI vs Selenide - Selenium CampRoman iovlev battle - JDI vs Selenide - Selenium Camp
Roman iovlev battle - JDI vs Selenide - Selenium Camp
 

Similar to Automation using Scripting and the Canvas API

Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stackPaul Bearne
 
Extending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh PollockExtending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh PollockCaldera Labs
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDmitriy Sobko
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On RailsJohn Wilker
 
Using the SugarCRM REST API
Using the SugarCRM REST APIUsing the SugarCRM REST API
Using the SugarCRM REST APIAsa Kusuma
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin developmentMostafa Soufi
 
Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013Mohan Arumugam
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsMichael Peacock
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCalderaLearn
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with PerlDave Cross
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Mario Cardinal
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Edureka!
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hackingJeroen van Dijk
 
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres OpenDavid Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres OpenPostgresOpen
 

Similar to Automation using Scripting and the Canvas API (20)

Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Extending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh PollockExtending the WordPress REST API - Josh Pollock
Extending the WordPress REST API - Josh Pollock
 
Designing REST API automation tests in Kotlin
Designing REST API automation tests in KotlinDesigning REST API automation tests in Kotlin
Designing REST API automation tests in Kotlin
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On Rails
 
Using the SugarCRM REST API
Using the SugarCRM REST APIUsing the SugarCRM REST API
Using the SugarCRM REST API
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013Power Shell and Sharepoint 2013
Power Shell and Sharepoint 2013
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Old WP REST API, New Tricks
Old WP REST API, New TricksOld WP REST API, New Tricks
Old WP REST API, New Tricks
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
Pyramid REST
Pyramid RESTPyramid REST
Pyramid REST
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
Python Flask Tutorial For Beginners | Flask Web Development Tutorial | Python...
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres OpenDavid Keeney - SQL Database Server Requests from the Browser @ Postgres Open
David Keeney - SQL Database Server Requests from the Browser @ Postgres Open
 

More from David Lippman

My Journey to Open - USNH ATI 2015
My Journey to Open - USNH ATI 2015My Journey to Open - USNH ATI 2015
My Journey to Open - USNH ATI 2015David Lippman
 
OER Update for FACTC Oct 2014
OER Update for FACTC Oct 2014OER Update for FACTC Oct 2014
OER Update for FACTC Oct 2014David Lippman
 
Automating Content Import
Automating Content ImportAutomating Content Import
Automating Content ImportDavid Lippman
 
Kaleidoscope Overview of Copyright
Kaleidoscope Overview of CopyrightKaleidoscope Overview of Copyright
Kaleidoscope Overview of CopyrightDavid Lippman
 
Open Course Library presentation, AMATYC 2013
Open Course Library presentation, AMATYC 2013Open Course Library presentation, AMATYC 2013
Open Course Library presentation, AMATYC 2013David Lippman
 
Santa Ana Open Math Forum
Santa Ana Open Math ForumSanta Ana Open Math Forum
Santa Ana Open Math ForumDavid Lippman
 
Understanding Copyright and Remixing by Example
Understanding Copyright and Remixing by ExampleUnderstanding Copyright and Remixing by Example
Understanding Copyright and Remixing by ExampleDavid Lippman
 

More from David Lippman (9)

My Journey to Open - USNH ATI 2015
My Journey to Open - USNH ATI 2015My Journey to Open - USNH ATI 2015
My Journey to Open - USNH ATI 2015
 
OER Update for FACTC Oct 2014
OER Update for FACTC Oct 2014OER Update for FACTC Oct 2014
OER Update for FACTC Oct 2014
 
The Case for Open
The Case for OpenThe Case for Open
The Case for Open
 
Automating Content Import
Automating Content ImportAutomating Content Import
Automating Content Import
 
Kaleidoscope Overview of Copyright
Kaleidoscope Overview of CopyrightKaleidoscope Overview of Copyright
Kaleidoscope Overview of Copyright
 
Open Course Library presentation, AMATYC 2013
Open Course Library presentation, AMATYC 2013Open Course Library presentation, AMATYC 2013
Open Course Library presentation, AMATYC 2013
 
Santa Ana Open Math Forum
Santa Ana Open Math ForumSanta Ana Open Math Forum
Santa Ana Open Math Forum
 
Understanding Copyright and Remixing by Example
Understanding Copyright and Remixing by ExampleUnderstanding Copyright and Remixing by Example
Understanding Copyright and Remixing by Example
 
Denver
DenverDenver
Denver
 

Recently uploaded

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Automation using Scripting and the Canvas API

  • 1. Automation using Scripting and the Canvas API David Lippman Pierce College Lumen Learning
  • 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/
  • 4. API “REST”: Basic GET/PUT/POST HTTP calls JSON format return https://domain.instructure.com/api/v1/courses
  • 5. Authentication HTTP Authorization Header Send access token in the query string https://domain.instructure.com/api/v1/courses?access_token=<ACCESS-TOKEN>
  • 10.
  • 11. So where does that get us? or Why should we care?
  • 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;
  • 15. The General Idea Grab the wiki page body.
  • 16. The General Idea Grab the wiki page body. Add attribution. $endpoint = “/api/v1/courses/$courseid/pages/$url”; $page = json_decode( file_get_contents( „https://‟.$domain.$endpoint. „?access_token='.$token )); $html = $page->body; $html .= $attribution;
  • 18. The General Idea Send back using CURL $endpoint = “/api/v1/courses/$courseid/pages/$url”; $ch = curl_init(„https://‟.$domain.$endpoint. „?access_token=‟.$token ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_POSTFIELDS, „wiki_page[body]=‟.urlencode($html)); $response = curl_exec($ch);
  • 19. Time to Library-ize require("canvaslib.php"); $api = new CanvasLMS($token,$domain); $pages = $api->getPageList($courseid); foreach ($pages as $id=>$name) { $body = $api->getPageData($courseid, $id, 'body'); $body .= $attribution; $api->updatePage($courseid, $id, array("body"=>$body)); }
  • 20. Use Case 2: Assignment Settings Adding Instructions to all Assignments in a course
  • 21. Use Case 2: Assignment Settings $assn = $api->getAssignmentList($courseid); foreach ($assn as $id=>$name) { $api->updateAssignment($courseid, $id, array(“description”=>$text)); }
  • 22. Use Case 3: Fixing links foreach ($pages as $id=>$name) { $body = $api->getPageData($courseid, $id, 'body'); $body = str_replace(“oldsite.com”,“newsite.com”, $body); $api->updatePage($courseid, $id, array("body"=>$body)); }
  • 23. Use Case 4: Removing Links foreach ($pages as $id=>$name) { $body = $api->getPageData($courseid, $id, 'body'); $body = preg_replace( '/<a[^>]*badsite[^>]*>(.*?)</a>/sm', ' $1 ', $body); $api->updatePage($courseid, $id, array("body"=>$body)); }
  • 24. Use Case 5: Rehosting Images preg_match_all( „/images.badsite.com[^>]*(gif|png|jpg)/„, $str, $matches); foreach ($matches[0] as $m) { $bn = basename($m); cp(„http://‟.$m, ‟./imgs/‟.$bn); $str = str_replace($m, „newhost.com/‟.$bn, $str); }
  • 25. General purpose, web-based tool Append Replace Search-and-replace Regex search-and-replace http://www.imathas.com/canvas/canvassearch.html Alternate Approach
  • 26. Working with Exports Upsides: • Can be faster for large numbers of pages • Can look at changes before uploading Downsides • Can’t 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)
  • 28.
  • 29. require("phpQuery-onefile.php"); $zip = new ZipArchive; $zip->open($file); phpQuery::newDocumentXML( $zip->getFromName("imsmanifest.xml")); $ref = pq("resource"); foreach ($ref as $r) { $reflist[pq($r)->attr("identifier")] = pq($r)->attr("href"); $reftype[pq($r)->attr("identifier")] = pq($r)->attr("type"); }
  • 30. $items = pq(“item”); foreach ($items as $item) { $iref = pq($item)->attr("identifierref"); if (isset($reftype[$iref]) && $reftype[$iref]=="webcontent") { $filename = $reflist[$iref]); $html = $zip->getFromName($filename); $html = str_replace(„</body>‟, $attribution.‟</body>‟, $html); $zip->addFromString($filename, $html); } }
  • 31. Sample Code https://github.com/drlippman/canvas-scripts • A simple library for doing API calls • A sample program using the library • The web-based general purpose tool • Search-and-replace in a cartridge example

Editor's Notes

  1. Before we start:Open up Canvas to a course with a few items in itOpen up general search-and-replace tool. Put in course ID and token