Replies: 1 comment 2 replies
-
The from canvasapi.util import combine_kwargs
# assuming you have a CSV or something
def enroll_user(course_id, **kwargs)
for user_id in sis_id_list:
kwargs["enrollment[sis_user_id:user_id]"] = user_id
# other params for the enrollment...
response = canvas._requester.request(
"POST",
"courses/12345/enrollments",
_kwargs=combine_kwargs(**kwargs),
)
return response.json() Note that I've not done this myself, but it should get you close. The |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The enroll_user() function of the Course class allows the enrollment of a user using a User object or the user's canvas id. From the docs:
enroll_user(user, enrollment_type=None, **kwargs)
Create a new user enrollment for a course or a section.
Calls:
POST /api/v1/courses/:course_id/enrollments
Parameters:
user (canvasapi.user.User or int) – The object or ID of the user to enroll in this course.
enrollment_type (str, optional) – The type of enrollment.
Return type:
canvasapi.enrollment.Enrollment
To my understanding, the canvas API allows users to be referenced by their sis_user_id simply by prefixing the id with "sis_user_id:". Using the sis_user_id in my current situation would be a lot better, because I would not need to call the api for the user's object and canvas ID. However, from reading the code and documentation, it seems this is not possible to do with this canvasAPI? I am iterating over many students to enroll them in courses, and doing the call to get each one's data individually takes some time. I believe using the sis_user_id instead would speed things up for me, since I don't have the canvas user id's stored in my database.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions