创建 educationAssignment
命名空间:microsoft.graph
创建新分配。
只有班级中的教师才能创建作业。 作业从“草稿”状态开始,这意味着学生在发布之前不会看到作业。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
EduAssignments.ReadWriteBasic、EduAssignments.ReadWrite |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
不支持。 |
HTTP 请求
POST /education/classes/{class-id}/assignments
| 标头 |
值 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json |
请求正文
在请求正文中,提供 educationAssignment 对象的 JSON 表示形式。
响应
如果成功,此方法在响应正文中返回 201 Created 响应代码和 educationAssignment 对象。
示例
请求
下面展示了示例请求。
POST https://graph.microsoft.com/v1.0/education/classes/72a7baec-c3e9-4213-a850-f62de0adad5f/assignments
Content-type: application/json
{
"dueDateTime": "2021-09-07T00:00:00Z",
"displayName": "Reading test 09.03 #4",
"instructions": {
"contentType": "text",
"content": "Read chapter 4"
},
"grading": {
"@odata.type": "#microsoft.graph.educationAssignmentGradeType",
"maxPoints": 50
},
"assignTo": {
"@odata.type": "#microsoft.graph.educationAssignmentGradeType"
},
"status": "draft",
"allowStudentsToAddResourcesToSubmission": true
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var educationAssignment = new EducationAssignment
{
DueDateTime = DateTimeOffset.Parse("2021-09-07T00:00:00Z"),
DisplayName = "Reading test 09.03 #4",
Instructions = new EducationItemBody
{
ContentType = BodyType.Text,
Content = "Read chapter 4"
},
Grading = new EducationAssignmentPointsGradeType
{
MaxPoints = 50f
},
AssignTo = new EducationAssignmentClassRecipient
{
},
Status = EducationAssignmentStatus.Draft,
AllowStudentsToAddResourcesToSubmission = true
};
await graphClient.Education.Classes["{educationClass-id}"].Assignments
.Request()
.AddAsync(educationAssignment);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const educationAssignment = {
dueDateTime: '2021-09-07T00:00:00Z',
displayName: 'Reading test 09.03 #4',
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);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/education/classes/72a7baec-c3e9-4213-a850-f62de0adad5f/assignments"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphEducationAssignment *educationAssignment = [[MSGraphEducationAssignment alloc] init];
[educationAssignment setDueDateTime: "2021-09-07T00:00:00Z"];
[educationAssignment setDisplayName:@"Reading test 09.03 #4"];
MSGraphEducationItemBody *instructions = [[MSGraphEducationItemBody alloc] init];
[instructions setContentType: [MSGraphBodyType text]];
[instructions setContent:@"Read chapter 4"];
[educationAssignment setInstructions:instructions];
MSGraphEducationAssignmentGradeType *grading = [[MSGraphEducationAssignmentGradeType alloc] init];
[grading setMaxPoints: 50];
[educationAssignment setGrading:grading];
MSGraphEducationAssignmentRecipient *assignTo = [[MSGraphEducationAssignmentRecipient alloc] init];
[educationAssignment setAssignTo:assignTo];
[educationAssignment setStatus: [MSGraphEducationAssignmentStatus draft]];
[educationAssignment setAllowStudentsToAddResourcesToSubmission: true];
NSError *error;
NSData *educationAssignmentData = [educationAssignment getSerializedDataWithError:&error];
[urlRequest setHTTPBody:educationAssignmentData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
EducationAssignment educationAssignment = new EducationAssignment();
educationAssignment.dueDateTime = OffsetDateTimeSerializer.deserialize("2021-09-07T00:00:00Z");
educationAssignment.displayName = "Reading test 09.03 #4";
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);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewEducationAssignment()
dueDateTime, err := time.Parse(time.RFC3339, "2021-09-07T00:00:00Z")
requestBody.SetDueDateTime(&dueDateTime)
displayName := "Reading test 09.03 #4"
requestBody.SetDisplayName(&displayName)
instructions := msgraphsdk.NewEducationItemBody()
requestBody.SetInstructions(instructions)
contentType := "text"
instructions.SetContentType(&contentType)
content := "Read chapter 4"
instructions.SetContent(&content)
grading := msgraphsdk.NewEducationAssignmentGradeType()
requestBody.SetGrading(grading)
grading.SetAdditionalData(map[string]interface{}{
"@odata.type": "#microsoft.graph.educationAssignmentPointsGradeType",
"maxPoints": ,
}
assignTo := msgraphsdk.NewEducationAssignmentRecipient()
requestBody.SetAssignTo(assignTo)
assignTo.SetAdditionalData(map[string]interface{}{
"@odata.type": "#microsoft.graph.educationAssignmentClassRecipient",
}
status := "draft"
requestBody.SetStatus(&status)
allowStudentsToAddResourcesToSubmission := true
requestBody.SetAllowStudentsToAddResourcesToSubmission(&allowStudentsToAddResourcesToSubmission)
educationClassId := "educationClass-id"
result, err := graphClient.Education().ClassesById(&educationClassId).Assignments().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Education
$params = @{
DueDateTime = [System.DateTime]::Parse("2021-09-07T00:00:00Z")
DisplayName = "Reading test 09.03 #4"
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
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
在请求正文中,提供 educationAssignment 对象的 JSON 表示形式。
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#education/classes('72a7baec-c3e9-4213-a850-f62de0adad5f')/assignments/$entity",
"classId": "72a7baec-c3e9-4213-a850-f62de0adad5f",
"displayName": "Reading test 09.03 #5",
"closeDateTime": null,
"dueDateTime": "2021-09-07T00:00:00Z",
"assignDateTime": null,
"assignedDateTime": null,
"allowLateSubmissions": true,
"resourcesFolderUrl": null,
"createdDateTime": "2021-09-03T23:57:14.6088791Z",
"lastModifiedDateTime": "2021-09-03T23:57:14.6398613Z",
"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%2272a7baec-c3e9-4213-a850-f62de0adad5f%5C%22,%5C%22displayName%5C%22%3Anull,%5C%22assignmentIds%5C%22%3A%5B%5C%224679bc1b-90c5-45af-ae1a-d5357672ed39%5C%22%5D%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",
"addedStudentAction": "none",
"id": "4679bc1b-90c5-45af-ae1a-d5357672ed39",
"instructions": {
"content": "Read chapter 5",
"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
}
}
}
另请参阅