[ARCHIVED] Canvas API & Python Scripts

bduggan96
Community Explorer

Hello All!

 

If you're looking for a quick way to change the visibility of a course navigation tab for all account courses, here's a Python script you could use that I created!

 

https://github.com/switchroute/Python/blob/master/canvasapitabfileshidden.py

 

All you have to do is input your API key, adjust the URL to your institution's Canvas URL, and adjust the for-loop of course numbers it will flip through to adjust the visibility of each tab.  In this code, it specifically is hiding the Files tab from students.  Some professors like to add their own course links that aren't necessary to the student's learning, so I have decided to mass-hide the Files tab - which doesn't hide the individual published links from view in the Modules/Assignments/etc.

 

This feature/script can hide any of your desired links (Files, Conferences, etc.), just not "Home" or "Settings". On average, the script takes from 30-40min to run, but it sure beats having to go through each course and hiding specific tabs over and over! Hope this helps, and let me know if you have any questions on it!

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Also, I have created the following Python script:

I was looking to do a similar task of adding a second login via API, as we are overhauling our adfs SSO mapping to better match our SIS.  With that said, I have linked my GitHub (Link 1) below to be able to copy my Python script.  I have also attached the documentation upon which I used to build this code (this article being one of them).  Essentially, you only need to create an API bearer token within Canvas (Link 2), copy that key into the two API fields within the Python Code which is commented, add in your school's URL link which is also commented, and tweak the code so that it is adding the desired secondary login to your Canvas account.

 

Currently the code runs and creates a secondary login with the user's email, whose initial login username is a SIS provided username.  You are able to change that field to whatever you would like as the POST request, but do ensure that they are unique usernames (ID number, email address, etc.)  It will also create a .txt document to show a log of students who were changed and/or ignored.

 

If you are wanting to update everyone's login credential, I would utilize the SIS Import feature (Link 3).  You possibly could change the Python script to have a PUT request instead, that also should work, but I would certainly recommend testing both of these scripts on your test site before moving on to your production site.

 

Depending on how many users you have, this code could take anywhere from 20min to 2hrs to run as it goes through every user and their login credentials.

Hope this is helpful!

Link 1: https://github.com/switchroute/Python/blob/master/canvasloginpostapicall.py

 

Link 2: https://community.canvaslms.com/t5/Admin-Guide/How-do-I-manage-API-access-tokens-as-an-admin/ta-p/89

 

Link 3: https://canvas.instructure.com/doc/api/file.sis_csv.html

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

If you are looking into how to use Python, here are some great resources to use!  The Canvas API in Python is fantastic, and Python is free.

Downloading Python:

https://www.python.org/downloads/

Setting Up Python in Path/Computer Environments:

PC: https://geek-university.com/python/add-python-to-the-windows-path/

Mac: https://www.educative.io/edpresso/how-to-add-python-to-the-path-variable-in-mac

Now you can open either Git Bash (on PC) or Terminal (Mac/Linux), and run the code with the following Python Command:

$ python "###" 

The ### would be the path to the Python scripts shown above, such as "C:\Users\user\Desktop\CanvasAPI\canvasloginpostapicall.py"

 

Hope this helps!

 

Labels (2)