Skip to content

Quiz content in an unsaved state after creating and adding questions #681

Open
@mhaffner

Description

@mhaffner

Describe the bug

There's a documented issue with the Canvas API (not the Python module) making quizzes being in an unsaved stated after creation. This results in the instructor having to manually save quizzes from the user interface so that students can see the questions. Supposedly triggering an edit using quiz.edit() should fix the issue but doesn't seem to work.

With the canvasapi python module, I can create quizzes, but I can't edit them after creation.

To Reproduce

from canvasapi import Canvas

url = "<uni_url_here>"
key = "<key_here>"
course_id = "<course_id_here>"

canvas = Canvas(url, key)
course = canvas.get_course(course_id)

attendance_question = {
    'question_name': 'standard_quiz_question',
    'question_text': 'Respond to something from class today! You can make a comment or ask a question. This should be 1-2 sentences.',
    'points_possible': 10,
    'question_type': 'essay_question',
}

for i in range(1):
    # create quiz item here
    quiz = course.create_quiz(quiz={
        'title': 'Reflection {}'.format(class_period_labels[i]),
        'quiz_type' : 'graded_survey',
        'description': '',
        'points_possible': 10,
        'access_code' : 123,
        'published' : False,
        'notify_of_update' : False
    })

    # add question to it here
    question = quiz.create_question(question=attendance_question)

    # the question has been added but this doesn't work; the quiz remains unpublished
    quiz.edit(published=True)

The quiz remains unpublished. If I initially set the quiz to published, I see this in Canvas:

"You have made changes to the questions in this quiz.
These changes will not appear for students until you save the quiz. "

Expected behavior

The quiz should publish using the Canvas API. I can publish it manually with curl:

curl -X PUT <uni_url_here>/api/v1/courses/<course_id_here>/quizzes/<quiz_id_here>" \
     -H "Authorization: Bearer <canvas_api_key_here>" \
     -H "Content-Type: application/json" \
     -d '{"quiz": {"published": true}}'

Environment information

  • Python version 3.12.7
  • CanvasAPI version 3.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions