@agatten1
Can I get a little clarification on "I am looking to create groups in sections of course prior to course migration?" In my experience, copying a course to another one does not copy existing groups. I copied a course with two different group sets and neither of them copied over to the new course. However, I did have a single "Project Groups" group set with no groups under it. If I copy a course with no group sets, then the copy has a "Groups" tab and a message about student groups being useful.
This lack of copying makes some sense because students are in the groups and the enrollments are not copied. The calls to automatically assign students to groups won't be applicable until there are students in the course as it wouldn't know how many groups to create.
What it seems like you're trying to do is automatically create groups in an existing course. This may mean that you need to create the course, add the students, and then run the group creation process.
I would use the Group Categories and Groups APIs.
If I'm understanding what you're trying to do properly, then this is what you will need to do for each course that has students in it (not the empty shell). This sounds like what you're describing. I did walk through the steps to verify that this works.
- Create a group category with a name and nothing else. This will create a group category (group set) with no groups under it. Make a note of the id in the response because this will become the group_category_id for other calls.
- Create a group and specify any unique names that you need. Use the id from step 1 as the group_category_id for this call. You will need to create the name so it is appropriate to the course. You may also need to incorporate a group number as part of the name so that you can distinguish the groups. If you are going to manually assign members, then note the id from the response because this will become the group_id for the next step. Repeat this step for each group that you need.
- Assign unassigned members will take distribute the students across the groups that you have created. Alternatively, if you want to assign people on your own, you would need to Create a membership using the group_id from step 2.
As for the second question, not everything that Canvas does is available through the API. If you want to have Canvas automatically create groups, then you are forced to live with group names that match the group set name with a number at the end. There is a create_group_count parameter when you create the group set.
Instead, what you need to do is to do the calculation on your own to determine the number of groups. The calculations vary based on whether you want a minimum of 4 students, a maximum of 4 students, or approximately 4 students in each group. There is no option for exactly 4 students per group (3 out of 4 sample sizes don't allow for exactly 4).
If you are willing to accept the Canvas generated names, then you can specify the number of groups to get a minimum of 4 students per group (assuming there are at least 4 students) or you can specify the limit on the number of students to get a maximum of 4.
Manually, generating a minimum of 4 involves something like this: number of groups = math.max(1,math.floor(number of students / 4)). You could have up to 7 students in one group this way.
Generating it so there is a maximum of 4 involves a calculation like: number of groups = math.ceil(number of students/4). Canvas tries to balance the groups so that 9 students would get groups of 3, 3, 3 rather than 4, 4, 1. The requirement is that it cannot exceed 4 in a group.
If you want about 4, but don't care if some groups go over a little, then you could use: number of groups = math.max(1,math.round(number of students/4)). Provided there are at least 3 students in the class, you never get more than 5 or less than 3 in a group this way. A group with 5 students occurs 1 time out of 4 while groups with 3 occur half the time.
Replace the math calculations by the appropriate function for whatever programming language you're using.
The number of groups you calculate manually factors into step 2 of the 3 step process above.
Note that all of this needs done in the Canvas course where there are students, not in a shell before a content migration. If your institution allows add/drops, it would be best to wait until close to the time when the groups are set to begin to make sure they are as accurate as they can (groups created early might experience students dropping so a group ends up with just one person).