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!
So, I started looking at using API to add and remove enrollments in 2019. At that time, I had mades calls to
/api/v1/accounts/86643/roles
And found that for us,
"id": 1208,
"role": "TeacherEnrollment",
"label": "Teacher",
That project got put on hold, but I'm picking it back up.
Today, when I get a teachers enrollment, I don't get back role_id 1208, rather, I'm not getting back for all teachers role_id 7743
If I call the account roles api, I also get back TeacherEnrollment of 7743, and I don't see role_id 1208 in this list
/api/v1/accounts/86643/roles
If I get the details of role 7743, I get back all the permissions I would expect for this role_id
/api/v1/accounts/86643/roles/7743
HOWEVER, I can still use the API to get back the details of the old role_id 1208
/api/v1/accounts/86643/roles/1208
With the ability to query/add roles by Name, I HAVE to use role_id, right? So, I should expect that I could 'hard code' role 1208 in my code and it would always work to add Teachers to courses. But my lived experience is that somewhere between 2019 and today, Instructure created a new TeacherEnrollment with a new role_id.
Should I hard code 7743 today and hope it doesn't change? Or do I need to make an expensive call to /roles to lookup whatever the current role_id for TeacherEnrollment is before every call to modify an enrollment? What's the best practice here?
Additional information.
Instructure lets me create/POST a new enrollment using the old 1208 role_id, and it adds them as a teacher. However, when I look at the enrollment record, Instructure has renumbered it to the 'current' 7743
I just set it to TeacherEnrollment. I don't specify a role. There are only two required fields to add an enrollment:
curl https://<canvas>/api/v1/courses/:course_id/enrollments \
-X POST \
-F 'enrollment[user_id]=2' \
-F 'enrollment[type]=TeacherEnrollment'
Will setting it to type TeacherEnrollment always work if you have custom roles that are based on TeacherEnrollment?
Oh! I had missed that enrollment[type] is actually a required element. That's interesting, I've not been using it.
@glparker wrote:
Will setting it to type TeacherEnrollment always work if you have custom roles that are based on TeacherEnrollment?
I'm not sure, we haven't really had any use cases for using a custom role for courses. We only use the account custom roles for people like principals or academic coaches to determine what they can see as an administrator.
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