cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cchan1
Community Member

Add enrollment via SIS ID or Login ID instead of Canvas User ID?

Jump to solution

I'm looking to enroll students in a course using the REST API, but in order to use the API I need to know the Canvas User ID. From the Enrollment API documentation for enrolling a user:

POST /api/v1/courses/:course_id/enrollments 

where a sample CURL request would be

curl https://<canvas>/api/v1/courses/:course_id/enrollments \
  -X POST \
  -F 'enrollment[user_id]=1' \
  -F 'enrollment[type]=StudentEnrollment' \
  -F 'enrollment[enrollment_state]=active' \
  -F 'enrollment[course_section_id]=1' \
  -F 'enrollment[limit_privileges_to_course_section]=true' \
  -F 'enrollment[notify]=false'

I unfortunately don't have the user_id to POST. I have the SIS ID or the Login ID, but not the user_id. The web interface allows me to add people to a course by specifying a SIS or Login ID, but that doesn't not appear to be the case with the enrollment API.

I tried passing enrollment[sis_user_id] and enrollment[sis_id], but that didn't work. I then searched the codebase and see that the enrollments api controller requires the existence of the user_id.

Is there a way to get the user id of a user given a particular SIS or login ID?

Thanks!

Tags (1)
1 Solution

Accepted Solutions
MattHanes
Community Champion

Howdy,

In many cases, you can pass the sis ID instead of the canvas ID. In the case of the SIS ID, you just have to send it like this instead: 

enrollment[user_id]=sis_user_id:000000

The documentation for this is located here in case I am not being clear: Object IDs, SIS IDs, and special IDs - Canvas LMS REST API Documentation 

View solution in original post

4 Replies
Stefanie
Community Team
Community Team

Hi,  @cchan1  Welcome  to the Canvas Community! Due to the technical nature of your question I've shared it with the https://community.canvaslms.com/groups/canvas-developers?sr=search&searchId=1e21e7f0-a33f-45c8-a7f2-... and https://community.canvaslms.com/groups/admins?sr=search&searchId=904b176d-3400-40f4-8ce9-d7b78c1a875...‌ groups. As their responses come in they will populate under this thread, but if you'd like to join one or both groups to participate directly in discussions there you can do so by clicking on the link to the group and selecting Join Group from the Actions dropdown that appears at the upper right of that page.

MattHanes
Community Champion

Howdy,

In many cases, you can pass the sis ID instead of the canvas ID. In the case of the SIS ID, you just have to send it like this instead: 

enrollment[user_id]=sis_user_id:000000

The documentation for this is located here in case I am not being clear: Object IDs, SIS IDs, and special IDs - Canvas LMS REST API Documentation 

View solution in original post

cchan1
Community Member

Wonderful! Thank you so much for the pointer - I was able to enroll users in a course via the API.

Thanks for the help and the quick reply!

ac3680
Community Member

This is really great! Does anyone know how we can get the SIS ID or UID with only an email address? I want to enroll users into my course. I posted a question about this. Any advice is appreciated!