cancel
Showing results for 
Search instead for 
Did you mean: 
kfavara
Community Participant

Error Posting to Enrollments - C#

Jump to solution

I am using C# to post to the API. I have been successful creating users and courses, however, I cannot seem to get my users enrolled. 

I have created the user using the API and I can successfully GET the user using https://url.instructure.com/api/v1/users/sis_user_id:usernumber

I have created the course and I can successfully GET the course using https://url.instructure.com/api/v1/courses/sis_course_id:coursenumber

I am sending a POST statement to 

https://url.instructure.com/api/v1/courses/sis_course_id:coursenumber/enrollments

and sending the json data of 
{"enrollment":{"sis_user_id":"usernumber","type":"TeacherEnrollment"}}

 

I receive a 403 error. I have admin rights and can create users with my user and token. I have read elsewhere that the 403 error can also mean bad data, but my data appears to be correct. 

Thanks for your help.

Labels (1)
Tags (4)
1 Solution

Accepted Solutions
jperkins
Instructure
Instructure

It should work if you change your parameters to look like:

{"enrollment":{"user_id":"sis_user_id:usernumber","type":"TeacherEnrollment"}}‍‍

View solution in original post

7 Replies
nnasir
Community Participant

The "sis_user_id" is a field that seems to only be in the response of the API and not one of the parameters that the call accepts when sending the request.

Try changing it to just 'user_id' and try again. The data being sent should look something like this with the user_id being an integer: 

{"enrollment": {"user_id": 1234567890,"type":"TeacherEnrollment"}}

I'm not sure how your environment is set up, but the user_id is the ID that Canvas assigns a person (and is listed in the URL of the user's profile) and not what the actual "sis_user_id" may be. In our instance, they are different.

Hope this helps! Good luck!

jperkins
Instructure
Instructure

It should work if you change your parameters to look like:

{"enrollment":{"user_id":"sis_user_id:usernumber","type":"TeacherEnrollment"}}‍‍

View solution in original post

kfavara
Community Participant

Yes, using user_id allowed it to successfully get past the API. Now, however, it Canvas picked the wrong user to enroll. This was a teacher enrollment, so there was only one user enrolled as a teacher. The ID that I posted was 000045. The ID that was enrolled as the teacher (which is a student, based on ID), was 1000364528. Weird!!

nnasir
Community Participant

Hmm..I didn't know that canvas allows user_ids with leading 0s. Is 000045 in the URL of the teacher's profile? E.g. url.instructure.com/accounts/1/users/000045

You could probably do a search for that ID using the users API to see what it returns as well to determine the user_id canvas is using for that particular teacher. 

kfavara
Community Participant

It does not allow user_ids with leading 0's. But, it does allow sis_user_id with them. I created the users with sis_user_id, courses with sis_course_id, etc. I should be able to match a user with sis_user_id if I created the user with that.

nnasir
Community Participant

Look at what  @jperkins  wrote below, I think his syntax would work best in your case then (I actually learned something new through his reply)

kfavara
Community Participant

Yes, this worked! Thank you so much for everyone's help!!