Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
I’m currently developing a Python project for a university that processes a PDF or CSV containing student IDs and their extended exam times. The goal is to automate the process of adding extra time to specific exams. During development, I realized I need the unique Canvas ID for each user, which appears in the URL when I click on a student’s profile, rather than just the student ID (which shows in the sis id column).
I’m trying to find a way to convert the student ID into the Canvas ID. Here’s the code I’ve written so far:
def _extract_info_from_csv(file):
self.df = pd.read_csv(file)
user_time_dict = {}
for sis_id in self.df['Student']:
try:
sis_id = int(sis_id) # Convert to int
print(f"Fetching user for SIS ID: {sis_id}")
user = self.canvas.get_user(sis_id, "sis_user_id") # Attempt to fetch the Canvas user ID
print(f"User retrieved: {user}") # Inspect the user object
if user:
canvas_id = user.id # Adjust this based on your actual user object structure
extension = self.df.loc[self.df['Student'] == sis_id, 'Extension'].values[0]
user_time_dict[canvas_id] = extension
else:
print(f"No user found for SIS ID: {sis_id}")
except Exception as e:
print(f"Error fetching user for SIS ID {sis_id}: {e}")
return user_time_dict
Unfortunately, the script isn't able to find the user based on the student ID, and am unable to convert the student ID to canvas unique ID. I don't know why. Any suggestions on how I might resolve this issue?
Solved! Go to Solution.
You can utilize your SIS ID as part of the URI for your API call using the following syntax.
/api/v1/users/sis_user_id:########/
More info can be found here:https://canvas.instructure.com/doc/api/file.object_ids.html.
Hope that helps!
You can utilize your SIS ID as part of the URI for your API call using the following syntax.
/api/v1/users/sis_user_id:########/
More info can be found here:https://canvas.instructure.com/doc/api/file.object_ids.html.
Hope that helps!
Hi, thanks for the response!
I'm using python and importing the canvas api and using the canvas object.
I'm not sure how to use that syntax with the canvas object. - Do you know how?
Also, Is there not a way to convert the SIS_ID into the canvas id?
To participate in the Instructure Community, you need to sign up or log in:
Sign In