Create educationAssignment
Article
09/27/2023
9 contributors
Feedback
In this article
Namespace: microsoft.graph
Create a new assignment.
Only teachers in a class can create an assignment. Assignments start in the Draft state, which means that students will not see the assignment until publication.
This API is supported in the following national cloud deployments .
Global service
US Government L4
US Government L5 (DOD)
China operated by 21Vianet
✅
❌
❌
❌
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
EduAssignments.ReadWriteBasic, EduAssignments.ReadWrite
Delegated (personal Microsoft account)
Not supported.
Application
EduAssignments.ReadWrite.All, EduAssignments.ReadWriteBasic.All
HTTP request
POST /education/classes/{class-id}/assignments
Header
Value
Authorization
Bearer {token}. Required.
Content-Type
application/json
Request body
In the request body, supply a JSON representation of an educationAssignment object.
Response
If successful, this method returns a 201 Created
response code and an educationAssignment object in the response body.
Example
Request
The following is an example of the request.
POST https://graph.microsoft.com/v1.0/education/classes/72a7baec-c3e9-4213-a850-f62de0adad5f/assignments
Content-type: application/json
{
"dueDateTime": "2022-09-16T00:00:00Z",
"displayName": "Reading test 09.14",
"instructions": {
"contentType": "text",
"content": "Read chapter 4"
},
"grading": {
"@odata.type": "#microsoft.graph.educationAssignmentPointsGradeType",
"maxPoints": 50
},
"assignTo": {
"@odata.type": "#microsoft.graph.educationAssignmentClassRecipient"
},
"status": "draft",
"allowStudentsToAddResourcesToSubmission": true
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new EducationAssignment
{
DueDateTime = DateTimeOffset.Parse("2022-09-16T00:00:00Z"),
DisplayName = "Reading test 09.14",
Instructions = new EducationItemBody
{
ContentType = BodyType.Text,
Content = "Read chapter 4",
},
Grading = new EducationAssignmentPointsGradeType
{
OdataType = "#microsoft.graph.educationAssignmentPointsGradeType",
MaxPoints = 50f,
},
AssignTo = new EducationAssignmentClassRecipient
{
OdataType = "#microsoft.graph.educationAssignmentClassRecipient",
},
Status = EducationAssignmentStatus.Draft,
AllowStudentsToAddResourcesToSubmission = true,
};
var result = await graphClient.Education.Classes["{educationClass-id}"].Assignments.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
// THE CLI IS IN PREVIEW. NON-PRODUCTION USE ONLY
mgc education classes assignments create --education-class-id {educationClass-id} --body '{\
"dueDateTime": "2022-09-16T00:00:00Z",\
"displayName": "Reading test 09.14",\
"instructions": {\
"contentType": "text",\
"content": "Read chapter 4"\
},\
"grading": {\
"@odata.type": "#microsoft.graph.educationAssignmentPointsGradeType",\
"maxPoints": 50\
},\
"assignTo": {\
"@odata.type": "#microsoft.graph.educationAssignmentClassRecipient"\
},\
"status": "draft",\
"allowStudentsToAddResourcesToSubmission": true\
}\
'
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
"time"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewEducationAssignment()
dueDateTime , err := time.Parse(time.RFC3339, "2022-09-16T00:00:00Z")
requestBody.SetDueDateTime(&dueDateTime)
displayName := "Reading test 09.14"
requestBody.SetDisplayName(&displayName)
instructions := graphmodels.NewEducationItemBody()
contentType := graphmodels.TEXT_BODYTYPE
instructions.SetContentType(&contentType)
content := "Read chapter 4"
instructions.SetContent(&content)
requestBody.SetInstructions(instructions)
grading := graphmodels.NewEducationAssignmentPointsGradeType()
maxPoints := float32(50)
grading.SetMaxPoints(&maxPoints)
requestBody.SetGrading(grading)
assignTo := graphmodels.NewEducationAssignmentClassRecipient()
requestBody.SetAssignTo(assignTo)
status := graphmodels.DRAFT_EDUCATIONASSIGNMENTSTATUS
requestBody.SetStatus(&status)
allowStudentsToAddResourcesToSubmission := true
requestBody.SetAllowStudentsToAddResourcesToSubmission(&allowStudentsToAddResourcesToSubmission)
assignments, err := graphClient.Education().Classes().ByEducationClassId("educationClass-id").Assignments().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
EducationAssignment educationAssignment = new EducationAssignment();
educationAssignment.dueDateTime = OffsetDateTimeSerializer.deserialize("2022-09-16T00:00:00Z");
educationAssignment.displayName = "Reading test 09.14";
EducationItemBody instructions = new EducationItemBody();
instructions.contentType = BodyType.TEXT;
instructions.content = "Read chapter 4";
educationAssignment.instructions = instructions;
EducationAssignmentPointsGradeType grading = new EducationAssignmentPointsGradeType();
grading.maxPoints = 50;
educationAssignment.grading = grading;
EducationAssignmentClassRecipient assignTo = new EducationAssignmentClassRecipient();
educationAssignment.assignTo = assignTo;
educationAssignment.status = EducationAssignmentStatus.DRAFT;
educationAssignment.allowStudentsToAddResourcesToSubmission = true;
graphClient.education().classes("72a7baec-c3e9-4213-a850-f62de0adad5f").assignments()
.buildRequest()
.post(educationAssignment);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const educationAssignment = {
dueDateTime: '2022-09-16T00:00:00Z',
displayName: 'Reading test 09.14',
instructions: {
contentType: 'text',
content: 'Read chapter 4'
},
grading: {
'@odata.type': '#microsoft.graph.educationAssignmentPointsGradeType',
maxPoints: 50
},
assignTo: {
'@odata.type': '#microsoft.graph.educationAssignmentClassRecipient'
},
status: 'draft',
allowStudentsToAddResourcesToSubmission: true
};
await client.api('/education/classes/72a7baec-c3e9-4213-a850-f62de0adad5f/assignments')
.post(educationAssignment);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW VERSION OF THE SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new EducationAssignment();
$requestBody->setDueDateTime(new \DateTime('2022-09-16T00:00:00Z'));
$requestBody->setDisplayName('Reading test 09.14');
$instructions = new EducationItemBody();
$instructions->setContentType(new BodyType('text'));
$instructions->setContent('Read chapter 4');
$requestBody->setInstructions($instructions);
$grading = new EducationAssignmentPointsGradeType();
$grading->setOdataType('#microsoft.graph.educationAssignmentPointsGradeType');
$grading->setMaxPoints(50);
$requestBody->setGrading($grading);
$assignTo = new EducationAssignmentClassRecipient();
$assignTo->setOdataType('#microsoft.graph.educationAssignmentClassRecipient');
$requestBody->setAssignTo($assignTo);
$requestBody->setStatus(new EducationAssignmentStatus('draft'));
$requestBody->setAllowStudentsToAddResourcesToSubmission(true);
$result = $graphServiceClient->education()->classes()->byEducationClassId('educationClass-id')->assignments()->post($requestBody)->wait();
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Import-Module Microsoft.Graph.Education
$params = @{
dueDateTime = [System.DateTime]::Parse("2022-09-16T00:00:00Z")
displayName = "Reading test 09.14"
instructions = @{
contentType = "text"
content = "Read chapter 4"
}
grading = @{
"@odata.type" = "#microsoft.graph.educationAssignmentPointsGradeType"
maxPoints =
}
assignTo = @{
"@odata.type" = "#microsoft.graph.educationAssignmentClassRecipient"
}
status = "draft"
allowStudentsToAddResourcesToSubmission = $true
}
New-MgEducationClassAssignment -EducationClassId $educationClassId -BodyParameter $params
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
# THE PYTHON SDK IS IN PREVIEW. FOR NON-PRODUCTION USE ONLY
graph_client = GraphServiceClient(request_adapter)
request_body = EducationAssignment(
due_date_time = "2022-09-16T00:00:00Z",
display_name = "Reading test 09.14",
instructions = EducationItemBody(
content_type = BodyType.Text,
content = "Read chapter 4",
),
grading = EducationAssignmentPointsGradeType(
odata_type = "#microsoft.graph.educationAssignmentPointsGradeType",
max_points = 50,
),
assign_to = EducationAssignmentClassRecipient(
odata_type = "#microsoft.graph.educationAssignmentClassRecipient",
),
status = EducationAssignmentStatus.Draft,
allow_students_to_add_resources_to_submission = True,
)
result = await graph_client.education.classes.by_classe_id('educationClass-id').assignments.post(body = request_body)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
In the request body, supply a JSON representation of an educationAssignment object.
Response
The following is an example of the response.
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#education/classes('f4a941ff-9da6-4707-ba5b-0eae93cad0b4')/assignments/$entity",
"classId": "f4a941ff-9da6-4707-ba5b-0eae93cad0b4",
"displayName": "Reading test 09.14",
"closeDateTime": null,
"dueDateTime": "2022-09-16T00:00:00Z",
"assignDateTime": null,
"assignedDateTime": null,
"allowLateSubmissions": true,
"resourcesFolderUrl": null,
"createdDateTime": "2022-09-14T21:23:17.8898549Z",
"lastModifiedDateTime": "2022-09-14T21:23:17.9055807Z",
"allowStudentsToAddResourcesToSubmission": true,
"status": "draft",
"notificationChannelUrl": null,
"webUrl": "https://teams.microsoft.com/l/entity/66aeee93-507d-479a-a3ef-8f494af43945/classroom?context=%7B%22subEntityId%22%3A%22%7B%5C%22version%5C%22%3A%5C%221.0%5C%22,%5C%22config%5C%22%3A%7B%5C%22classes%5C%22%3A%5B%7B%5C%22id%5C%22%3A%5C%22f4a941ff-9da6-4707-ba5b-0eae93cad0b4%5C%22,%5C%22displayName%5C%22%3Anull,%5C%22assignmentIds%5C%22%3A%5B%5C%22ea77e1dd-1e04-4051-967e-09129d42290f%5C%22%5D,%5C%22submissionId%5C%22%3Anull%7D%5D%7D,%5C%22action%5C%22%3A%5C%22navigate%5C%22,%5C%22view%5C%22%3A%5C%22assignment-viewer%5C%22%7D%22,%22channelId%22%3Anull%7D",
"addToCalendarAction": "none",
"addedStudentAction": "none",
"id": "ea77e1dd-1e04-4051-967e-09129d42290f",
"instructions": {
"content": "Read chapter 4",
"contentType": "text"
},
"grading": {
"@odata.type": "#microsoft.graph.educationAssignmentPointsGradeType",
"maxPoints": 50
},
"assignTo": {
"@odata.type": "#microsoft.graph.educationAssignmentClassRecipient"
},
"createdBy": {
"application": null,
"device": null,
"user": {
"id": "f3a5344e-dbde-48b0-be24-b5b62a243836",
"displayName": null
}
},
"lastModifiedBy": {
"application": null,
"device": null,
"user": {
"id": "f3a5344e-dbde-48b0-be24-b5b62a243836",
"displayName": null
}
}
}
See also