Canvas LMS REST API Quiz creation

830 views Asked by At

I'm having an issue with quiz creation using the Canvas REST API:

I can create a new quiz with title set.

I can add N questions with the following parameters set:

  • question_name
  • question_text
  • question_type
  • points_possible
  • answers

When I look at my quizzes page, I can see the quiz exists, but it only shows that 1 question has been created for the quiz. I have to go to the quiz page, click the Edit button and then save the quiz for all of the questions to show up on the quizzes page.

What am I missing in this workflow?

2

There are 2 answers

2
dogwynn On BEST ANSWER

So, for anyone interested in this question, the best solution I've been able to find is a hack. I tried doing comparisons of the quiz model data structure returned both before and after manually saving the quiz. There were some trivial differences, but only a couple meaningful ones. The only relevant difference was in the question_count attribute. It isn't being updated after adding questions.

To "fix" this: after adding your questions, manually update the question_count attribute (via a PUSH).

Perhaps this is a bug, perhaps I don't know what I'm doing. Either way, if anyone else has a better understanding of the Canvas REST API, please comment or provide a better answer.

0
dsavransky On

Just ran into this same issue and here's a possible fix: Create the quiz first with published set to False. Add your questions. Then edit the quiz (https://canvas.instructure.com/doc/api/quizzes.html#method.quizzes/quizzes_api.update) to set published to True. Then add any overrides, etc.