Hi all,
I'm new to Canvas and to the API, and I'm tasked with migrating quizzes from another system to our Canvas instance. Mostly these are multiple choice questions. I can create questions via the API, but I haven't been able to do so if I include the answers. Here's an example JSON for a question I created manually, minus the Canvas-created IDs and empty values and null values:
{
"points_possible": 10.0,
"neutral_comments_html": "<p>mojito ergo sum</p>",
"correct_comments_html": "<p>Yea and verily</p>",
"question_text": "<p>This is a multiple choice question.</p>",
"incorrect_comments_html": "<p>plz no do not want</p>",
"question_type": "multiple_choice_question",
"quiz_id": 4683,
"question_name": "Question",
"answers": [
{
"weight": 100.0,
"text": "This is the correct answer.",
"comments_html": "<p>Well done!</p>"
},
{
"weight": 0.0,
"text": "Nahh.",
"comments_html": "<p>Nope. Nuh-uh.</p>"
},
{
"weight": 0.0,
"text": "Nacho cheese.",
"comments_html": "<p>Not in this lifetime.</p>"
},
{
"weight": 0.0,
"text": "Don't even look at it.",
"comments_html": "<p>Not now. Not ever.</p>"
}
],
"quiz_group_id": 2766,
"assessment_question_id": 109,
"position": 1
}
When I adapt it to function as the POST data for an API call to create a question, e.g. by wrapping the object keys in "question[...]", I get an internal server error (500) response from the server. Here's the data I posted:
{
"question[incorrect_comments_html]": "<p>plz no do not want</p>",
"question[question_text]": "<p>This is a multiple choice question.</p>",
"question[quiz_id]": 4683,
"question[points_possible]": 10.0,
"question[correct_comments_html]": "<p>Yea and verily</p>",
"question[neutral_comments_html]": "<p>mojito ergo sum</p>",
"question[assessment_question_id]": 109,
"question[question_type]": "multiple_choice_question",
"question[position]": 1,
"question[question_name]": "Question",
"question[answers]": [
{
"text": "This is the correct answer.",
"comments_html": "<p>Well done!</p>",
"weight": 100.0
},
{
"text": "Nahh.",
"comments_html": "<p>Nope. Nuh-uh.</p>",
"weight": 0.0
},
{
"text": "Nacho cheese.",
"comments_html": "<p>Not in this lifetime.</p>",
"weight": 0.0
},
{
"text": "Don't even look at it.",
"comments_html": "<p>Not now. Not ever.</p>",
"weight": 0.0
}
],
"question[quiz_group_id]": 2766
}
If I leave the `question[answer]` array empty, I can create the question. But with over 18000 multiple choice questions to migrate for just one semester's worth of courses, that leaves a tremendous amount of work to be done manually.
I've found hints in the groups and in the Canvas feature ideas forum that the API doesn't cover this functionality yet:
https://groups.google.com/d/msg/canvas-lms-users/U9XJtmwXLTk/xj0S21K1BIMJhttps://community.canvaslms.com/ideas/2348This feature idea suggests that it is possible, but I can't make out from its text how it works:
https://community.canvaslms.com/ideas/2348The API docs themselves are silent on the matter.
Has anyone succeeded in creating multiple choice questions with answers via the API? If so, would you kindly set me straight on how to format the JSON payload to accomplish this?
Many thanks,
Chuck