question

TechTT-9359 avatar image
0 Votes"
TechTT-9359 asked TechTT-9359 edited

Updating education outcome results in 400 Bad request

Hi,

I'm trying to update and education outcome of type EducationPointsOutcome and the requests always return error 400 Bad request: "The content of the request is invalid. Common causes are an invalid Content-Type header or no content in the body."

I'm using PHP SDK library and the code is the following:

 $outcome = new Microsoft\Graph\Model\EducationPointsOutcome();
 $points = new Microsoft\Graph\Model\EducationAssignmentPointsGrade();
 $points->setPoints(floatval($grade));
 $outcome->setPoints($points);
    
 $graph
     ->createRequest('PATCH', "/education/classes/{$classId}/assignments/{$assignmentId}/submissions/{$submissionId}/outcomes/{$outcomeId}")
     ->addHeaders(["Content-Type" => "application/json"])
     ->attachBody($outcome)
     ->execute();

Is there anyone that can help me with that? I don't know what's the problem because I followed the documentation in Update outcome page



microsoft-graph-education
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @TechTT-9359 , can you please provide more details about the request body?
In case that you have a requestId in the response please provide it too.

0 Votes 0 ·
TechTT-9359 avatar image TechTT-9359 CristobalBuenrostro-8227 ·

Thanks I figured what the problem was

1 Vote 1 ·

1 Answer

TechTT-9359 avatar image
2 Votes"
TechTT-9359 answered TechTT-9359 edited

Ok I found the problem. The thing was that I was updating an EducationOutcome by creating a new instance of EducationPointsOutcome to be able to access setPoints method, but I found out that I can do that if I keep the old EducationOutcome instance properties, like this

 $outcomes = $graph
     ->createCollectionRequest(
         'GET',
         "/education/classes/{$classId}/assignments/{$assignmentId}/submissions/{$submissionId}/outcomes"
     )
     ->addHeaders(["Content-Type" => "application/json"])
     ->setReturnType(Microsoft\Graph\Model\EducationOutcome::class)
     ->execute();
    
 $educationOutcome = null;
 foreach ($outcomes as $o) {
     if ($o->getODataType() === '#microsoft.graph.educationPointsOutcome') {
         $educationOutcome = $o;
     }
 }
    
 if (!is_null($educationOutcome)) {
     $outcome = new Microsoft\Graph\Model\EducationPointsOutcome($educationOutcome->getProperties());
     $points = new Microsoft\Graph\Model\EducationAssignmentPointsGrade();
     $points->setPoints($grade);
     $outcome->setPoints($points);
    
     $graph
         ->createRequest(
             'PATCH',
             "/education/classes/{$classId}/assignments/{$assignmentId}/submissions/{$submissionId}/outcomes/{$educationOutcome->getId()}"
         )
         ->addHeaders(["Content-Type" => "application/json"])
         ->attachBody($outcome)
         ->execute();
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.