Stay organized with collections
Save and categorize content based on your preferences.
An Invitation resource in Classroom represents an invitation
for a user to join a course with a specific course role: student, teacher,
or owner.
Each Invitation resource contains the following fields:
id: Classroom-assigned identifier for the invitation.
userId: The ID of the user that has been invited to the course.
courseId: The course that the user is being invited to.
role: The course role that the invited user will have in the course.
Create an Invitation
The invitations.create() method can be used to invite a user to a course
with a specific role. Include the Invitation resource in the request body
and specify the courseId, userId, and role.
Invitationinvitation=null;try{/* Set the role the user is invited to have in the course. Possible values of CourseRole can be found here: https://developers.google.com/classroom/reference/rest/v1/invitations#courserole.*/Invitationcontent=newInvitation().setCourseId(courseId).setUserId(userId).setRole("TEACHER");invitation=service.invitations().create(content).execute();System.out.printf("User (%s) has been invited to course (%s).\n",invitation.getUserId(),invitation.getCourseId());}catch(GoogleJsonResponseExceptione){// TODO (developer) - handle error appropriatelyGoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The course or user does not exist.\n");}throwe;}catch(Exceptione){throwe;}returninvitation;
Retrieve an Invitation
Retrieve a specific invitation by calling the invitations.get() method
and specifying the id of the invitation.
Invitationinvitation=null;try{invitation=service.invitations().get(id).execute();System.out.printf("Invitation (%s) for user (%s) in course (%s) retrieved.\n",invitation.getId(),invitation.getUserId(),invitation.getCourseId());}catch(GoogleJsonResponseExceptione){GoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The invitation id (%s) does not exist.\n",id);}throwe;}catch(Exceptione){throwe;}returninvitation;
Accept an Invitation
Accepting an invitation deletes the invitation and adds the invited
user to the course with the role specified in the invitation. Accept an
invitation by calling the invitations.accept() method and specifying the
id of the invitation.
try{service.invitations().accept(id).execute();System.out.printf("Invitation (%s) was accepted.\n",id);}catch(GoogleJsonResponseExceptione){GoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The invitation id (%s) does not exist.\n",id);}throwe;}catch(Exceptione){throwe;}
Delete an Invitation
The only way to update an invitation is to delete it and create a new
invitation. To delete the invitation, call the invitations.delete() method
and specify the id.
try{service.invitations().delete(id).execute();System.out.printf("Invitation (%s) was deleted.\n",id);}catch(GoogleJsonResponseExceptione){GoogleJsonErrorerror=e.getDetails();if(error.getCode()==404){System.out.printf("The invitation id (%s) does not exist.\n",id);}throwe;}catch(Exceptione){throwe;}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-01-14 UTC."],[[["An Invitation resource in Classroom allows users to join a course with a specific role, containing fields like `id`, `userId`, `courseId`, and `role`."],["You can create, retrieve, accept, and delete invitations using the Classroom API's `invitations` methods, specifying necessary parameters like `courseId`, `userId`, `role`, and `id`."],["Accepting an invitation adds the user to the course with the specified role and deletes the invitation, while deleting an invitation requires using the `invitations.delete()` method."],["Updating an invitation involves deleting the existing one and creating a new one with the desired changes."]]],[]]