AnsweredAssumed Answered

quiz submission update api - missing key ":quiz_submissions"

Question asked by Stephen Jensen on Apr 11, 2018
Latest reply on Oct 30, 2018 by rogrant@nmsu.edu

We have a mass orientation course with a single manually graded quiz that I need to get scored for LOTS of submissions (give 0 on all, so that gradebook calculates properly).  Doing this manually isn't an option.

 

Using - Quiz Submissions - Canvas LMS REST API Documentation 

 

When I run my script (included below) I'm getting a JSON respone wiht an error, the message being 

 

missing required key :quiz_submissions

 

If I json_encode() my data and print the results, I can see the quiz_submission property/object  and it appears to be the same as the examples in the docs -

{"quiz_submissions":[{"attempt":1,"questions":{"41418910":{"score":0,"comment":null}}}]}

 

Ideas?  Code:

 

<?php

// bring in API token as $access_token
include('token.php');

// which server and URL and such - hard coded for now
$server="https://courses.sfcollege.edu";
$url="/api/v1/courses/359214/quizzes/718805/submissions/6173765";

// the data
$qd['attempt']=1;
$qd['questions']["41418910"]['score']=0;
$qd['questions']["41418910"]['comment']=null;

$qq['quiz_submissions']=array($qd);

// print(json_encode($qq)."\n");
// {"quiz_submissions":[{"attempt":1,"questions":{"41418910":{"score":0,"comment":null}}}]}

$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$server.$url);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Authorization: Bearer ".$access_token));
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"PUT");
curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($qq));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$curl_result=curl_exec($ch);
curl_close($ch);
$result=json_decode($curl_result);
print_r($result);

/*

stdClass Object
(
[status] => bad_request
[message] => missing required key :quiz_submissions
[error_report_id] => 32591645
)


*/

?>

Outcomes