Saving Quizzes w/ API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've written a simple script to add a series of quizzes to the end of each module in a department.
There's some other stuff happening around this to figure out the title, answers, and some other pieces, but the code at the bottom shows my API requests to create the quiz and then to add a question to the quiz.
The quiz and question is created fine, but if a student takes the quiz, the question does not show up. If an instructor opens the quiz, there is a message saying the instructor must first save the quiz. If they click the save button, the questions then show up for students.
Is there a way to simulate that save action with the API?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have only used the quiz API to modified an existing quiz by adding questions and then published it from within Canvas. Within the web interface, I have noticed that if the quiz is published and I go back and make substantial questions, I get warning messages and the changes aren't updated unless I click a button to save. That makes me wonder if it's the fact that it's published before I add the questions that causes the problem?
I cannot find an example right now to recreate. That means that the following is based off of knowledge and understanding of the API and how things work in general, but I have not tested it specifically with your case.
What I notice in your code is that you publish the quiz upon creation and then you add questions to it.
Have you tried creating the quiz to get a shell, adding the questions, and then edit the quiz to add the particulars, including that it is published? It may be that just the published=true is needed as part of the edit after the quiz is created, again -- I'm doing this without testing.
The "Save Quiz" button uses an internal (non-API) AJAX call, but that doesn't mean that the functionality isn't there that just updates the setting (not whether or not it is published). In other words, you may be able to just call the edit the quiz endpoint to get it working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just needed to solve this same problem. This solution is not correct so I want to get the correct answer posted in case anyone runs into the same problem.
If you edit a quiz via the API and the quiz is published, then it will enter a draft state where you need to save the quiz via the user interface. To avoid this you need to unpublish the quiz before making edits:
1. Unpublish the quiz, note I always set "notify_of_update" as part of all edits as the documentation lists this as a parameter: