What's the deal with changing role_id's

glparker
Community Champion

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?  

 

 

 

 

Labels (1)
0 Likes