The Canvas website is designed for human interaction, with visual elements to facilitate ease of use. The Canvas API however allows you to access the underlying data directly for use with other systems. You can use the API to do many things, such as streamline grading, access course rosters, and manage assignments.
This article outlines the steps required to access and utilize the Canvas API. For a general introduction to APIs and a detailed walk-through of using the Canvas API and its functions, please see this Canvas Developers Group article.
Generating Your Canvas Access Token
To interact with the API, you’ll need an access token, a unique string (like a password) which acts as the secure access credential for your Canvas data.
- Log into Canvas: Navigate to https://jhu.instructure.com/ and log in with your credentials.
-
Access Your Account Settings: Click the Account link in the left-side navigation menu and proceed to Settings.
-
Generate a New Token:
- Scroll down to the Approved Integration section and click + New Access Token.
- Provide a descriptive purpose (e.g., "Research Project Automation").
- Assign an expiration date for additional security.
- Click Generate Token and copy the result.
- Scroll down to the Approved Integration section and click + New Access Token.
Important: Do not share your token publicly or with unauthorized third parties. If the token is compromised, delete it immediately using the settings menu.
Making Your First API Call With Curl
Now that you have a token, let’s explore how to use it. The following example demonstrates making a simple API call to retrieve profile details associated with your Canvas account.
-
Open the appropriate terminal application for your operating system:
- Mac users: Open the Terminal app by searching for it via Spotlight.
- Windows users: Use Command Prompt. (Windows users may first need to install Git for Curl to run properly. Users of current versions of Windows 10 and 11 should already have Curl installed.)
-
Enter the Curl Command: curl https://jhu.instructure.com/api/v1/users/self -H "Authorization: Bearer $token"
Replace "$token" with the access token generated earlier.
- Review the Response: After executing the command, you should receive a JSON response similar to this:
{"id":12345,"name":"Example Name","created_at":"1975-11-15T14:58:54-05:00",
"sortable_name":"Name, Example","short_name":"Example Name","pronouns":
"He/Him/His","avatar_url":"https://jhu.instructure.com/images/messages/avatar-50.png",
"last_name":"Name","first_name":"Example","locale":null,"effective_locale":"en",
"permissions":{"can_update_name":false,"can_update_avatar":true,
"limit_parent_app_web_access":false}}
Now that you have successfully queried the Canvas API and received a response to confirm that your credentials and access are functioning, you are now ready to start using your token for your project.
What data this token makes available to you is dependent upon your Canvas user account's permissions and enrollments. For faculty, you will be able to interact with courses where you have the "Instructor" role. You can use the API to create a comprehensive list of these enrollments with the commands outlined here: Canvas API documentation for the 'List your courses' function
Additional Resources
-
Canvas Developers Group API Guide
- This document is designed to assist everyone from those that have never heard the API acronym before, to seasoned programming veterans who may be looking for tips and tricks that are specific to the Canvas API.
-
Canvas LMS API Documentation
- Comprehensive documentation of the functions and syntax of the Canvas REST API.
-
Canvas 101 Video: Guide to Using the Canvas API
- This video walks the user through an example usage of the Canvas API in action.