Canvas Group Creation

Create canvas group via Canvas API

source

CanvasGroup

 CanvasGroup (credentials_fp='', API_URL='https://canvas.ucsd.edu',
              course_id='', group_category='', verbosity=1)

Initialize Canvas Group within a Group Set and its appropriate memberships

Type Default Details
credentials_fp str credential file path. Template of the credentials.json
API_URL str https://canvas.ucsd.edu the domain name of canvas
course_id str Course ID, can be found in the course url
group_category str target group category (set) of interests
verbosity int 1 Controls the verbosity: 0 = Silent, 1 = print all messages

Lower Level Methods

Alternatively, you can manually set them after you created the CanvasGroup object


source

CanvasGroup.auth_canvas

 CanvasGroup.auth_canvas (credentials_fp:str)

Authorize the canvas module with API_KEY

Type Details
credentials_fp str the Authenticator key generated from canvas

source

CanvasGroup.set_course

 CanvasGroup.set_course (course_id:int)

Set the target course by the course ID

Type Details
course_id int the course id of the target course

The following tutorial and examples demonstrates how to create and set a Group Category within a course context.

Create / Set Target Group Category (Set)


source

CanvasGroup.get_group_categories

 CanvasGroup.get_group_categories ()

Grab all existing group categories (group set) in this course

# list all current group category
list(cg.get_group_categories().keys())
['Final Project', 'Student Groups', 'Test']

source

CanvasGroup.create_group_category

 CanvasGroup.create_group_category (params:dict)

Create group category (group set) in this course

Type Details
params dict the parameter of canvas group category API @ this link
Returns GroupCategory the generated group category object
params = {
    "name": "TEST-GroupProject",
    "group_limit": 5
}
# create a new category
group_category = cg.create_group_category(params)
# Check whether we successfully create a new group
list(cg.get_group_categories().keys())
['Final Project', 'Student Groups', 'Test', 'TEST-GroupProject']

When a group category is already created, we cannot create another group with the same name. To switch the group category destination of group creation, use the set_group_category methods.


source

CanvasGroup.set_group_category

 CanvasGroup.set_group_category (category_name:str)
Type Details
category_name str the target group category
Returns GroupCategory target group category object
group_category = cg.set_group_category("TEST-GroupProject")

Create a Group Inside the Target Group Category


source

CanvasGroup.create_group

 CanvasGroup.create_group (params:dict)

Create canvas group under the target group category

Type Details
params dict the parameter of canvas group create API at this link
Returns Group the generated target group object
params = {
    "name": "TEST-GROUP1",
    "join_level": "invitation_only"
}
group1 = cg.create_group(params)
print(group1)
In Group Set: TEST-GroupProject,
Group TEST-GROUP1 Created!
TEST-GROUP1 (122854)

Assign Student to the Group


source

CanvasGroup.join_canvas_group

 CanvasGroup.join_canvas_group (group:canvasapi.group.Group,
                                group_members:[<class'str'>])

Add membership access of each group member into the group

Type Details
group Group the group that students will join
group_members [<class ‘str’>] list of group member’s SIS Login (email prefix, before the @.)
Returns [<class ‘str’>] list of unsuccessful join
member1 = "email"

cg.join_canvas_group(group1, [member1])
[]