Created
March 6, 2017 17:12
-
-
Save battis/59d693298d02b76ab1bb2dc3880c3712 to your computer and use it in GitHub Desktop.
Accessing the Canvas APIs via JavaScript
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
<html> | |
<body> | |
<!-- load JQuery: copied and pasted from the JQuery CDN list --> | |
<script | |
src="https://code.jquery.com/jquery-3.1.1.min.js" | |
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" | |
crossorigin="anonymous"></script> | |
<script> | |
/* | |
* this allows us to make authenticated API requests to Canvas | |
* as a particular user -- you can get your own token in your | |
* Canvas User Profile | |
*/ | |
var token = 'get-your-own-dang-token'; | |
/** | |
* Function to handle the response from the API | |
* @param JSON response | |
*/ | |
function handleResponse(response) { | |
console.log(response); | |
} | |
/* | |
* Make the API call and pass the response to our handleResponse | |
* function | |
*/ | |
$.ajax({ | |
/* | |
* Request all of the submissions information for all assignments | |
* and students in a particular course -- this is the raw data | |
*/ | |
'url': 'https://stmarksschool.instructure.com/api/v1/courses/181/students/submissions', | |
'headers': { | |
/* | |
* this allows us to make authenticated API requests to Canvas | |
* as a particular user -- you can get your own token in your | |
* Canvas User Profile | |
*/ | |
'Authorization': 'Bearer ' + token | |
}, | |
'type': 'GET', | |
'data': { | |
'student_ids': 'all', | |
'grouped': true, | |
'include': ['assignment', 'total_scores', 'course', 'user'] | |
}, | |
'success': handleResponse | |
}); | |
$.ajax({ | |
/* | |
* Request all of the analytics data about all the assignments in a | |
* particular course -- this is the rankings data | |
*/ | |
'url': 'https://stmarksschool.instructure.com/api/v1/courses/181/analytics/assignments', | |
'headers': { | |
/* | |
* this allows us to make authenticated API requests to Canvas | |
* as a particular user -- you can get your own token in your | |
* Canvas User Profile | |
*/ | |
'Authorization': 'Bearer ' + token | |
}, | |
'type': 'GET', | |
'data': { | |
}, | |
'success': handleResponse | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment