When creating an automated data integration with Canvas, you should practice using the API to import SIS data to Canvas. One method of using an API is through cURL, a command line tool for transferring data that is supported on all operating systems (Windows, Linux, and OSX). In this lesson, examples should work with Windows 7+, Windows Server 2003+, Ubuntu 12+ (Desktop/Server), and OSX Mountain Lion+.
The examples in this lesson are provided to help you learn how to practice using the API to import content into Canvas using SIS imports.
On your computer or operating system, ensure that cURL is installed properly on your computer or operating system.
OS X & Linux (Ubuntu)
cURL should already be installed and run from the Terminal application.
cURL may already be installed. If not already installed, run the following command with a user that has sudo privileges:
sudo apt-get install curl
After installing cURL, test the installation by typing the following command on a terminal or command prompt:
If successfully installed, the version of cURL should be displayed.
If you are planning to use Windows as your import server you should consider using PowerShell instead of cURL for your production import tool. PowerShell is native to Windows and should result in a more reliable import script than using cURL and a batch file. We only recommend using cURL on Windows for testing purposes. Learn how to install PowerShell on Windows.
Practice using the API before adding the complexity of a script.
curl -F attachment=@test_course.csv -H "Authorization: Bearer <api_token>" 'https://<canvas_fqdn>/api/v1/accounts/self/sis_imports.json?import_type=instructure_csv'
Upon success, you should receive a string of JSON back from the server that indicates the import has been created and provides an ID for the import job. The JSON will look something like:
The "id" and "workflow_state" parameters are important pieces of information to know as you develop your script. Their absence or value could indicate a problem. If you did not get an "id" parameter, or your "workflow_state" tag is anything other than created, you will need to troubleshoot the cause before proceeding.
Note: When this command is complete, you'll need the "id" parameter to check the status of an import.
An important part of the automated import process is to know the status of your previous import before processing your next import.
If you decide to do a standard import, you must fix the previous import before processing your next import because information may be lost from the failed/incomplete import job. If you are using full batch imports, the state is still important because you do not want to start your next full batch until the preceding batch has finished. Depending on your update frequency, size of import, and other factors, a full batch import could easily overrun your time window.
Run the following command with these replacements:
curl -H "Authorization: Bearer <api_token>" 'https://<canvas_fqdn>/api/v1/accounts/self/sis_imports/<import_id>'
The command should return a JSON response that contains the status and result if the import is complete. The following is an example of result of the command run in the previous step:
Here are a few key points to consider regarding the JSON results:
progress: In a running job, the "progress" parameter indicates the percentage complete for the job. When a job is done running, the progress will be 100 percent.
workflow_state: The "workflow_state" parameter indicates the current state of a running job. In most cases, a successfully completed job will indicate a state of "imported." If you see anything other than "imported" or "importing," you will need to stop here and troubleshoot the cause before proceeding.