Create Education Assignment returns “20132” error using microsoft graph api at c#

Brass Contributor

I want to create a specific class of assignments.

At Graph Explorer,{classId}/assignments


This request works well.

But in my C# code,


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



It occured error:



{"Code: 20132\r\nMessage: The content of the request is invalid. Common causes are an invalid Content-Type header or no content in the body.\r\nInner error:\r\n\tAdditionalData:\r\n\tdate: 2020-09-20T07:25:14\r\n\trequest-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n\tclient-request-id: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\nClientRequestId: d2181119-9116-4f1d-9ed4-d007e2e406d0\r\n"}


Why is this happening? I've been thinking and trying all day.


I tried


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


But there was the same error.

If only the displayname element was requested, the results were the same.

The Permissions has been dealt with. EduAssignments.ReadWriteBasic, EduAssignments.ReadWrite.. etc And the dll(NuGet pakage) is also prepared in beta version.

I referred to this document. 

I'm desperate for help.. Thanks.

0 Replies