AnsweredAssumed Answered

Creating a custom role using a Canvas API

Question asked by Dave Dieckmeyer on Dec 7, 2017
Latest reply on Dec 15, 2017 by Stuart Ryan

I realized that we needed to create a few custom roles in our primary account and decided to give it a try using the API provided in the API documentation. It seemed simple enough, but I'm having trouble getting the permissions to apply based on the rules in the description. I use this site to paste any curl that's offered ( see the curl source at the bottom of the 'Create a new role' section in the api docs ) to get an idea of how I should be formatting my Python code, then I tweak it.

 

This is the result:

 

import requests

headers = {
   'Authorization': 'Bearer <token>',
}

 

files = {
   'label': (None, 'New Role'),

   'base_role_type': (None,'TaEnrollment'),
   'permissions[read_course_content][explicit]': (None, '1'),
   'permissions[read_course_content][enabled]': (None, '1'),
   'permissions[read_course_list][locked]': (None, '1'),
   'permissions[read_question_banks][explicit]': (None, '1'),
   'permissions[read_question_banks][enabled]': (None, '0'),
   'permissions[read_question_banks][locked]': (None, '1'),
}

requests.get('https://<canvas>/api/v1/accounts/:account_id/roles.json', headers=headers, files=files)

 

After running the script, the role is created but without any of the permissions as written. I added the 'base_role_type' to the mix and it creates it accordingly. What I don't get is when I change the 'None' or '1' to something different as described in the documentation, it doesn't change the permissions of the newly created role. 

 

Any ideas about what might be going on and how to correct it so I can customize a new role?

 

Thanks,

      Dave

Outcomes