Microsoft图形 API - 创建教育作业返回"20132"错误



我想创建一个特定的赋值类。

在图形浏览器,

https://graph.microsoft.com/beta/education/classes/{classId}/assignments

这个请求运行良好。

但在我的C#代码中,

var assignInfo = new EducationAssignment
{
DisplayName = "test",

DueDateTime = DateTimeOffset.Parse("2020-09-20T18:00:00Z"),
Instructions = new EducationItemBody
{
ContentType = BodyType.Html,
Content = "hi"
},
Status = EducationAssignmentStatus.Draft,
AllowStudentsToAddResourcesToSubmission = true,

AssignTo = new EducationAssignmentClassRecipient
{
},
Grading = new EducationAssignmentPointsGradeType()
{
MaxPoints = 100
},
CreatedDateTime = DateTimeOffset.Parse("2020-09-20T12:00:00Z"),
AssignDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),
AssignedDateTime = DateTimeOffset.Parse("2020-09-20T13:00:00Z"),

CloseDateTime = null,

AllowLateSubmissions = true

};
await graphClient.Education.Classes[pClassId].Assignments
.Request()

.AddAsync(assignInfo);

发生错误:

{"Code: 20132rnMessage: The content of the request is invalid. Common causes are an invalid Content-Type header or no content in the body.rnInner error:rntAdditionalData:rntdate: 2020-09-20T07:25:14rntrequest-id: d2181119-9116-4f1d-9ed4-d007e2e406d0rntclient-request-id: d2181119-9116-4f1d-9ed4-d007e2e406d0rnClientRequestId: d2181119-9116-4f1d-9ed4-d007e2e406d0rn"}

为什么会发生这种情况?我一整天都在思考和尝试。

我试过

await graphClient.Education.Classes[pClassId].Assignments
.Request()
.Header("Content-Type", "application/json")
.AddAsync(assignInfo);

但也有同样的错误。

如果只请求了displayname元素,则结果是相同的。

权限已得到处理。EduAssignments.ReadWriteBasic、EduAssignments.LeadWrite..等dll(NuGet-pakage(也是在测试版中准备的。

我提到了这份文件。

我迫切需要帮助。。谢谢

添加此assignInfo.ODataType = null;可以修复问题。

相关内容

  • 没有找到相关文章

最新更新