Your Community is getting an upgrade!
Read about our partnership with Higher Logic and how we will build the next generation of the Instructure Community.
Found this content helpful? Log in or sign up to leave a like!
I have been exercising the APi a bit now for an integration project I am working on.
One of the few issues I am having involves setting a user as an observer while enrolling a student in a course.
Before I get to this point, I have:
Added two users through the API using PHP:
URI: accounts/self/users
Params:
'pseudonym' => [
'unique_id' => $args['email'],
'password' => $args['password'],
'integration_id' => $args['uId'],
'send_confirmation' => false
],
'user' => [
'name' => $args['first_name'] . ' ' . $args['last_name'],
'sortable_name' => $args['last_name'] . ', ' . $args['first_name'],
'skip_registration' => true
],
'communication_channel' => [
'type' => 'email',
'address' => $args['email'],
'skip_confirmation' => true
]
Both users appear to be created correctly, and then I move on to assign one of the users to a course as a student, and assign the other as an observer:
URI: courses/'<course ID>/enrollments
$oid = <Canvas user ID for the intended observer>
$sid = <Canvas user ID for the intended student>
Params:
'user_id' => $oid,
'enrollment_type' => 'ObserverEnrollment',
'role' => 'Observer',
'enrollment' => [
'user_id' => $sid,
'type' => 'StudentEnrollment'
]
The good:
The student is changed to type 'student'
The student is enrolled in the course
The ugly (and why I am here):
The parent is not assigned an observer role
The parent is not changed to type 'observer'
Am I missing something simple? Or am I misunderstanding a basic API principle as implemented by Canvas?
Seriously appreciate any help or feedback!
Thanks,
Rick
Solved! Go to Solution.
Hi @Rickpunzel,
I'm not familiar with PHP at all, but I'll infer some of the syntax from your post and hope it's correct. Looking at the enrollments API, I think your enrollment params objects should look more like the following:
For the student:
'enrollment' => [
'user_id' => $sid,
'type' => 'StudentEnrollment'
]
For the observer:
'enrollment' => [
'user_id' => $oid,
'type' => 'ObserverEnrollment',
'associated_user_id' => '$sid
]
Basically, an enrollment always needs enrollment[user_id] which is the Canvas_id of the user you're working with, and enrollment[type] which is what kind of role you want the user to have. For the observer-type roles, a third piece of information is needed, enrollment[associated_user_id] which is the canvas_is of the user you want this enrollment to observe. You can of course use more parameters if you wish, but those are the bare minimum. I hope this may solve your issue!
-Chris
Hi @Rickpunzel,
I'm not familiar with PHP at all, but I'll infer some of the syntax from your post and hope it's correct. Looking at the enrollments API, I think your enrollment params objects should look more like the following:
For the student:
'enrollment' => [
'user_id' => $sid,
'type' => 'StudentEnrollment'
]
For the observer:
'enrollment' => [
'user_id' => $oid,
'type' => 'ObserverEnrollment',
'associated_user_id' => '$sid
]
Basically, an enrollment always needs enrollment[user_id] which is the Canvas_id of the user you're working with, and enrollment[type] which is what kind of role you want the user to have. For the observer-type roles, a third piece of information is needed, enrollment[associated_user_id] which is the canvas_is of the user you want this enrollment to observe. You can of course use more parameters if you wish, but those are the bare minimum. I hope this may solve your issue!
-Chris
Thank you for the suggestion! It lead me on the right path to solve my issue 🙂
I was trying to do everything in one pass, but in looking through the documentation for the 100th time, I found an easier approach to what I was really trying to do.
I will add that here, as anyone viewing this answer is likely trying the same thing?
To assign a user as an observer to another user account (assuming a parent/student relationship here):
PUT /api/v1/users/{observer ID}/observees/{observee ID}
Thanks again!
Rick
To interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign InTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign In