Groups API
Groups serve as the data for a few different ideas in Canvas. The first is that they can be a community in the canvas network. The second is that they can be organized by students in a course, for study or communication (but not grading). The third is that they can be organized by teachers or account administrators for the purpose of projects, assignments, and grading. This last kind of group is always part of a group category, which adds the restriction that a user may only be a member of one group per category.
All of these types of groups function similarly, and can be the parent context for many other types of functionality and interaction, such as collections, discussions, wikis, and shared files.
Group memberships are the objects that tie users and groups together.
A Group object looks like:
{ // The ID of the group. id: 17, // The display name of the group. name: "Math Group 1", // A description of the group. This is plain text. description: null, // Whether or not the group is public. Currently only community groups // can be made public. Also, once a group has been set to public, it // cannot be changed back to private. is_public: false, // Whether or not the current user is following this group. followed_by_user: false, // How people are allowed to join the group. For all groups except for // community groups, the user must share the group's parent course or // account. For student organized or community groups, where a user // can be a member of as many or few as they want, the applicable // levels are "parent_context_auto_join", "parent_context_request", and // "invitation_only". For class groups, where students are divided up // and should only be part of one group of the category, this value // will always be "invitation_only", and is not relevant. // // * If "parent_context_auto_join", anyone can join and will be // automatically accepted. // * If "parent_context_request", anyone can request to join, which // must be approved by a group moderator. // * If "invitation_only", only those how have received an // invitation my join the group, by accepting that invitation. join_level: "invitation_only", // The number of members currently in the group members_count: 0, // The url of the group's avatar avatar_url: "https://<canvas>/files/avatar_image.png", // The course or account that the group belongs to. The pattern here is // that whatever the context_type is, there will be an _id field named // after that type. So if instead context_type was "account", the // course_id field would be replaced by an account_id field. context_type: "Course", course_id: 3, // Certain types of groups have special role designations. Currently, // these include: "communities", "student_organized", and "imported". // Regular course/account groups have a role of null. role: null, // The ID of the group's category. group_category_id: 4, // the storage quota for the group, in megabytes storage_quota_mb: 50 }
A Group Membership object looks like:
{ // The id of the membership object id: 92 // The id of the group object to which the membership belongs group_id: 17 // The id of the user object to which the membership belongs user_id: 3 // The current state of the membership. Current possible values are // "accepted", "invited", and "requested" workflow_state: "accepted" // Whether or not the user is a moderator of the group (the must also // be an active member of the group to moderate) moderator: true }
List your groups GroupsController#index
GET /api/v1/users/self/groups
Returns a list of active groups for the current user.
Request Parameters:
-
context_type
- Optional
-
only include groups that are in this type of
context. Can be 'Account' or 'Course'
Example Request:
curl https://<canvas>/api/v1/users/self/groups?context_type=Account \ -H 'Authorization: Bearer <token>'
List the groups available in a context. GroupsController#context_index
GET /api/v1/accounts/:account_id/groups
GET /api/v1/courses/:course_id/groups
Returns the list of active groups in the given context that are visible to user.
Example Request:
curl https://<canvas>/api/v1/courses/1/groups \ -H 'Authorization: Bearer <token>'
Get a single group GroupsController#show
GET /api/v1/groups/:group_id
Returns the data for a single group, or a 401 if the caller doesn't have the rights to see it.
Example Request:
curl https://<canvas>/api/v1/groups/<group_id> \ -H 'Authorization: Bearer <token>'
Create a group GroupsController#create
POST /api/v1/groups
POST /api/v1/group_categories/:group_category_id/groups
Creates a new group. Groups created using the "/api/v1/groups/" endpoint will be community groups.
Request Parameters:
-
name
the name of the group
-
description
a description of the group
-
is_public
whether the group is public (applies only to community groups)
-
join_level
parent_context_auto_join, parent_context_request, or invitation_only
-
storage_quota_mb
The allowed file storage for the group, in megabytes. This parameter is ignored if the caller does not have the manage_storage_quotas permission.
Example Request:
curl https://<canvas>/api/v1/groups \ -F 'name=Math Teachers' \ -F 'description=A place to gather resources for our classes.' \ -F 'is_public=true' \ -F 'join_level=parent_context_auto_join' \ -H 'Authorization: Bearer <token>'
Edit a group GroupsController#update
PUT /api/v1/groups/:group_id
Modifies an existing group. Note that to set an avatar image for the group, you must first upload the image file to the group, and the use the id in the response as the argument to this function. See the File Upload Documentation for details on the file upload workflow.
Request Parameters:
- name
- description
-
is_public
Currently you cannot set a group back to private once it has been made public.
- join_level
-
avatar_id
The id of the attachment previously uploaded to the group that you would like to use as the avatar image for this group.
-
storage_quota_mb
The allowed file storage for the group, in megabytes. This parameter is ignored if the caller does not have the manage_storage_quotas permission.
Example Request:
curl https://<canvas>/api/v1/groups/<group_id> \ -X PUT \ -F 'name=Algebra Teachers' \ -F 'join_level=parent_context_request' \ -H 'Authorization: Bearer <token>'
Delete a group GroupsController#destroy
DELETE /api/v1/groups/:group_id
Deletes a group and removes all members.
Example Request:
curl https://<canvas>/api/v1/groups/<group_id> \ -X DELETE \ -H 'Authorization: Bearer <token>'
Follow a group GroupsController#follow
BETA: This API endpoint is not finalized, and there could be breaking changes before its final release.
PUT /api/v1/groups/:group_id/followers/self
Follow this group. If the current user is already following the group, nothing happens. The user must have permissions to view the group in order to follow it.
Responds with a 401 if the user doesn't have permission to follow the group.
Example Request:
curl https://<canvas>/api/v1/groups/<group_id>/followers/self \ -X PUT \ -H 'Content-Length: 0' \ -H 'Authorization: Bearer <token>'
Example Response:
{ following_user_id: 5, followed_group_id: 6, created_at: <timestamp> }
Un-follow a group GroupsController#unfollow
BETA: This API endpoint is not finalized, and there could be breaking changes before its final release.
DELETE /api/v1/groups/:group_id/followers/self
Stop following this group. If the current user is not already following the group, nothing happens.
Example Request:
curl https://<canvas>/api/v1/groups/<group_id>/followers/self \ -X DELETE \ -H 'Authorization: Bearer <token>'
Invite others to a group GroupsController#invite
POST /api/v1/groups/:group_id/invite
Sends an invitation to all supplied email addresses which will allow the receivers to join the group.
Request Parameters:
-
invitees
An array of email addresses to be sent invitations
Example Request:
curl https://<canvas>/api/v1/groups/<group_id>/invite \ -F 'invitees[]=leonard@example.com&invitees[]=sheldon@example.com' \ -H 'Authorization: Bearer <token>'
List group's users GroupsController#users
GET /api/v1/groups/:group_id/users
Returns a list of users in the group.
Request Parameters:
-
search_term
(optional) The partial name or full ID of the users to match and return in the results list. Must be at least 3 characters.
Example Request:
curl https://<canvas>/api/v1/groups/1/users \ -H 'Authorization: Bearer <token>'
Upload a file GroupsController#create_file
POST /api/v1/groups/:group_id/files
Upload a file to the group.
This API endpoint is the first step in uploading a file to a group. See the File Upload Documentation for details on the file upload workflow.
Only those with the "Manage Files" permission on a group can upload files to the group. By default, this is anybody participating in the group, or any admin over the group.
Preview processed html GroupsController#preview_html
POST /api/v1/groups/:group_id/preview_html
Preview html content processed for this group
Request Parameters:
-
html
The html content to process
Example Request:
curl https://<canvas>/api/v1/groups/<group_id>/preview_html \ -F 'html=<p><badhtml></badhtml>processed html</p>' \ -H 'Authorization: Bearer <token>'
Example Response:
{ "html": "<p>processed html</p>" }
Group activity stream GroupsController#activity_stream
GET /api/v1/groups/:group_id/activity_stream
Returns the current user's group-specific activity stream, paginated.
For full documentation, see the API documentation for the user activity stream, in the user api.
Group activity stream summary GroupsController#activity_stream_summary
GET /api/v1/groups/:group_id/activity_stream/summary
Returns a summary of the current user's group-specific activity stream.
For full documentation, see the API documentation for the user activity stream summary, in the user api.
List group memberships GroupMembershipsController#index
GET /api/v1/groups/:group_id/memberships
GET /api/v1/groups/:group_id/users
List the members of a group.
Request Parameters:
-
filter_states[]
- Optional
-
Only list memberships with the given
workflow_states. Allowed values are "accepted", "invited", and "requested". By default it will return all memberships.
Example Request:
curl https://<canvas>/api/v1/groups/<group_id>/memberships \ -F 'filter_states[]=invited&filter_states[]=requested' \ -H 'Authorization: Bearer <token>'
Create a membership GroupMembershipsController#create
POST /api/v1/groups/:group_id/memberships
Join, or request to join, a group, depending on the join_level of the group. If the membership or join request already exists, then it is simply returned
Request Parameters:
- user_id
Example Request:
curl https://<canvas>/api/v1/groups/<group_id>/memberships \ -F 'user_id=self' -H 'Authorization: Bearer <token>'
Update a membership GroupMembershipsController#update
PUT /api/v1/groups/:group_id/memberships/:membership_id
PUT /api/v1/groups/:group_id/users/:user_id
Accept a membership request, or add/remove moderator rights.
Request Parameters:
-
workflow_state
Currently, the only allowed value is "accepted"
- moderator
Example Request:
curl https://<canvas>/api/v1/groups/<group_id>/memberships/<membership_id> \ -F 'moderator=true' -H 'Authorization: Bearer <token>'
curl https://<canvas>/api/v1/groups/<group_id>/users/<user_id> \ -F 'moderator=true' -H 'Authorization: Bearer <token>'
Leave a group GroupMembershipsController#destroy
DELETE /api/v1/groups/:group_id/memberships/:membership_id
DELETE /api/v1/groups/:group_id/users/:user_id
Leave a group if you are allowed to leave (some groups, such as sets of course groups created by teachers, cannot be left). You may also use 'self' in place of a membership_id.
Example Request:
curl https://<canvas>/api/v1/groups/<group_id>/memberships/<membership_id> \ -X DELETE \ -H 'Authorization: Bearer <token>'
curl https://<canvas>/api/v1/groups/<group_id>/users/<user_id> \ -X DELETE \ -H 'Authorization: Bearer <token>'