Last active
September 12, 2024 18:38
-
-
Save cms-jakes/751cf7cacfc59e63491338cba6359e9e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// CANVAS API Call Template | |
// by Jake Standish [[email protected]] | |
// Written December, 2016 | |
// You are free to copy and moodify this code at your own risk. | |
// | |
// INSTRUCTIONS | |
// 1. Copy this code. | |
// 2. Open a google apps script file from a Google Spreadsheet, Form, Document, or Google Apps Script (script.google.com). | |
// 3. Obtain your access token from Canvas and paste it's value in the parenthese after var accessToken = | |
// 4. Enter your Canvas domain url between parentheses after var domain = | |
// 5. Begin writing function that call cAPI to call data from Canvas. | |
// Example: | |
// The following example returns an object containing informaiton about courses you are enrolled in as a teacher. It will return up to 100 courses. | |
// var data = cAPI('GET', '/api/v1/courses?enrollment_type=teacher&per_page=100') | |
// | |
// RESOURCES | |
// How to get your access token: https://community.canvaslms.com/docs/DOC-3013 | |
// Canvas API documentation: https://canvas.instructure.com/doc/api/ | |
// | |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
function getHeader(){ | |
var properties = PropertiesService.getScriptProperties(); | |
var accessToken = ""; //paste your access token between the parentheses. | |
var domain = ""; //type your domain url between the parentheses. (https://domainName.instructure.com) | |
properties.setProperties({accessToken: accessToken, domain: domain}) | |
var header = {'Authorization':'Bearer '+accessToken}; | |
return header; | |
} | |
function cAPI(method,url) { | |
var params = { | |
'headers': getHeader(), | |
'method': method | |
} | |
var domain = PropertiesService.getScriptProperties().getProperty('domain') | |
//Retrieve data from Canvas | |
var call = UrlFetchApp.fetch(domain+url,params); | |
var data = JSON.parse(call); | |
var headers = call.getAllHeaders(); | |
return data; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
// CANVAS API Call Template | |
// by Jake Standish [[email protected]] | |
// Written December, 2016 | |
// You are free to copy and moodify this code at your own risk. | |
// | |
// INSTRUCTIONS | |
// 1. Copy this code. | |
// 2. Open a google apps script file from a Google Spreadsheet, Form, Document, or Google Apps Script (script.google.com). | |
// 3. Obtain your access token from Canvas and paste it's value in the parenthese after var accessToken = | |
// 4. Enter your Canvas domain url between parentheses after var domain = | |
// 5. Begin writing function that call cAPI to call data from Canvas. | |
// Example: | |
// The following example returns an object containing informaiton about courses you are enrolled in as a teacher. It will return up to 100 courses. | |
// var data = cAPI('GET', '/api/v1/courses?enrollment_type=teacher&per_page=100') | |
// | |
// RESOURCES | |
// How to get your access token: https://community.canvaslms.com/docs/DOC-3013 | |
// Canvas API documentation: https://canvas.instructure.com/doc/api/ | |
// | |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
function getHeader(){ | |
var properties = PropertiesService.getScriptProperties(); | |
var accessToken = ""; //paste your access token between the parentheses. | |
var domain = ""; //type your domain url between the parentheses. (https://domainName.instructure.com) | |
properties.setProperties({accessToken: accessToken, domain: domain}) | |
var header = {'Authorization':'Bearer '+accessToken}; | |
return header; | |
} | |
function cAPI(method,url) { | |
var params = { | |
'headers': getHeader(), | |
'method': method | |
} | |
var domain = PropertiesService.getScriptProperties().getProperty('domain') | |
//Retrieve data from Canvas | |
var call = UrlFetchApp.fetch(domain+url,params); | |
var data = JSON.parse(call); | |
var headers = call.getAllHeaders(); | |
return data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment