Quiz

class canvasapi.quiz.Quiz(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

broadcast_message(conversations, **kwargs)

Send a message to unsubmitted or submitted users for the quiz.

Calls:

POST /api/v1/courses/:course_id/quizzes/:id/submission_users/message

Parameters:

conversations (dict) – A dictionary representing a Conversation. Requires ‘body’, ‘recipients’, and ‘subject’ keys.

Returns:

True if the message was created, False otherwize

Return type:

bool

create_question(**kwargs)

Create a new quiz question for this quiz.

Calls:

POST /api/v1/courses/:course_id/quizzes/:quiz_id/questions

Return type:

canvasapi.quiz.QuizQuestion

create_question_group(quiz_groups, **kwargs)

Create a new question group for the given quiz id

Calls:

POST /api/v1/courses/:course_id/quizzes/:quiz_id/groups

Parameters:

quiz_groups (list[dict]) – The name, pick count, question points, and/or assessment question bank id. All of these parameters are optional, but at least one must exist (even if empty) to receive a response. The request expects a list, but will only create 1 question group per request.

Returns:

QuizGroup object

Return type:

canvasapi.quiz_group.QuizGroup

create_report(report_type, **kwargs)

Create and return a new report for this quiz. If a previously generated report matches the arguments and is still current (i.e. there have been no new submissions), it will be returned.

Calls:

POST /api/v1/courses/:course_id/quizzes/:quiz_id/reports

Parameters:

report_type (str) – The type of report, either student_analysis or item_analysis

Returns:

QuizReport object

Return type:

canvasapi.quiz.QuizReport

create_submission(**kwargs)

Start taking a Quiz by creating a QuizSubmission can be used to answer questions and submit answers.

Calls:

POST /api/v1/courses/:course_id/quizzes/:quiz_id/submissions

Return type:

canvasapi.quiz.QuizSubmission

delete(**kwargs)

Delete this quiz.

Calls:

DELETE /api/v1/courses/:course_id/quizzes/:id

Return type:

canvasapi.quiz.Quiz

edit(**kwargs)

Modify this quiz.

Calls:

PUT /api/v1/courses/:course_id/quizzes/:id

Returns:

The updated quiz.

Return type:

canvasapi.quiz.Quiz

get_all_quiz_reports(**kwargs)

Get a list of all quiz reports for this quiz

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/reports

Return type:

canvasapi.paginated_list.PaginatedList of canvasapi.quiz.QuizReport

get_question(question, **kwargs)

Get as single quiz question by ID.

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/questions/:id

Parameters:

question (int, str or canvasapi.quiz.QuizQuestion) – The object or ID of the quiz question to retrieve.

Return type:

canvasapi.quiz.QuizQuestion

get_questions(**kwargs)

List all questions for a quiz.

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/questions

Return type:

canvasapi.paginated_list.PaginatedList of canvasapi.quiz.QuizQuestion

get_quiz_group(id, **kwargs)

Get details of the quiz group with the given id

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/groups/:id

Parameters:

id (int) – The ID of the question group.

Returns:

QuizGroup object

Return type:

canvasapi.quiz_group.QuizGroup

get_quiz_report(id, **kwargs)

Returns the data for a single quiz report.

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id

Parameters:

id (int or canvasapi.quiz.QuizReport) – The ID of the quiz report you want to retrieve, or the report object

Returns:

QuizReport object

Return type:

canvasapi.quiz.QuizReport

get_quiz_submission(quiz_submission, **kwargs)

Get a single quiz submission.

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/submissions/:id

Parameters:

quiz_submission (int, string, canvasapi.quiz.QuizSubmission) – The object or ID of the quiz submission to retrieve.

Return type:

canvasapi.quiz.QuizSubmission

get_statistics(**kwargs)

Get statistics for for all quiz versions, or the latest quiz version.

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/statistics

Return type:

canvasapi.paginated_list.PaginatedList of canvasapi.quiz.QuizStatistic

get_submissions(**kwargs)

Get a list of all submissions for this quiz.

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/submissions

Return type:

canvasapi.paginated_list.PaginatedList of canvasapi.quiz.QuizSubmission

set_extensions(quiz_extensions, **kwargs)

Set extensions for student quiz submissions.

Calls:

POST /api/v1/courses/:course_id/quizzes/:quiz_id/extensions

Parameters:

quiz_extensions (list) – List of dictionaries representing extensions.

Return type:

list of canvasapi.quiz.QuizExtension

Example Usage:

>>> quiz.set_extensions([
...     {
...         'user_id': 1,
...         'extra_time': 60,
...         'extra_attempts': 1
...     },
...     {
...         'user_id': 2,
...         'extra_attempts': 3
...     },
...     {
...         'user_id': 3,
...         'extra_time': 20
...     }
... ])

QuizAssignmentOverrideSet

class canvasapi.quiz.QuizAssignmentOverrideSet(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

QuizExtension

class canvasapi.quiz.QuizExtension(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

QuizQuestion

class canvasapi.quiz.QuizQuestion(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

delete(**kwargs)

Delete an existing quiz question.

Calls:

DELETE /api/v1/courses/:course_id/quizzes/:quiz_id/questions/:id

Returns:

True if question was successfully deleted; False otherwise.

Return type:

bool

edit(**kwargs)

Update an existing quiz question.

Calls:

PUT /api/v1/courses/:course_id/quizzes/:quiz_id/questions/:id

Return type:

canvasapi.quiz.QuizQuestion

QuizReport

class canvasapi.quiz.QuizReport(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

abort_or_delete(**kwargs)

This API allows you to cancel a previous request you issued for a report to be generated. Or in the case of an already generated report, you’d like to remove it, perhaps to generate it another time with an updated version that provides new features.

Calls:

DELETE /api/v1/courses/:course_id/quizzes/:quiz_id/reports/:id

Returns:

True if attempt was successful; False otherwise

Return type:

bool

QuizStatistic

class canvasapi.quiz.QuizStatistic(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

QuizSubmission

class canvasapi.quiz.QuizSubmission(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

answer_submission_questions(validation_token=None, **kwargs)

Provide or update an answer to one or more quiz questions.

Calls:

POST /api/v1/quiz_submissions/:quiz_submission_id/questions

Parameters:

validation_token (str) – (Optional) The unique validation token for this quiz submission. If one is not provided, canvasapi will attempt to use self.validation_token.

Returns:

A list of quiz submission questions.

Return type:

list of canvasapi.quiz.QuizSubmissionQuestion

complete(validation_token=None, **kwargs)

Complete the quiz submission by marking it as complete and grading it. When the quiz submission has been marked as complete, no further modifications will be allowed.

Calls:

POST /api/v1/courses/:course_id/quizzes/:quiz_id/submissions/:id/complete

Parameters:

validation_token (str) – (Optional) The unique validation token for this quiz submission. If one is not provided, canvasapi will attempt to use self.validation_token.

Return type:

canvasapi.quiz.QuizSubmission

get_submission_events(**kwargs)

Retrieve the set of events captured during a specific submission attempt.

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/submissions/:id/events

Returns:

PaginatedList of QuizSubmissionEvents.

Return type:

canvasapi.paginated_list.PaginatedList of canvasapi.quiz.QuizSubmissionEvent

get_submission_questions(**kwargs)

Get a list of all the question records for this quiz submission.

Calls:

GET /api/v1/quiz_submissions/:quiz_submission_id/questions

Returns:

A list of quiz submission questions.

Return type:

list of canvasapi.quiz.QuizSubmissionQuestion

get_times(**kwargs)

Get the current timing data for the quiz attempt, both the end_at timestamp and the time_left parameter.

Calls:

GET /api/v1/courses/:course_id/quizzes/:quiz_id/submissions/:id/time

Return type:

dict

submit_events(quiz_submission_events, **kwargs)

Store a set of events which were captured during a quiz taking session.

Calls:

POST /api/v1/courses/:course_id/quizzes/:quiz_id/submissions/:id/events

Parameters:

quiz_submission_events (list) – The submission events to be recorded.

Returns:

True if the submission was successful, false otherwise.

Return type:

bool

update_score_and_comments(**kwargs)

Update the amount of points a student has scored for questions they’ve answered, provide comments for the student about their answer(s), or simply fudge the total score by a specific amount of points.

Calls:

PUT /api/v1/courses/:course_id/quizzes/:quiz_id/submissions/:id

Returns:

The updated quiz.

Return type:

canvasapi.quiz.QuizSubmission

QuizSubmissionEvent

class canvasapi.quiz.QuizSubmissionEvent(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

QuizSubmissionQuestion

class canvasapi.quiz.QuizSubmissionQuestion(requester, attributes)
Parameters:
  • requester (canvasapi.requester.Requester) – The requester to pass HTTP requests through.

  • attributes (dict) – The JSON object to build this object with.

flag(validation_token=None, **kwargs)

Set a flag on a quiz question to indicate that it should be returned to later.

Calls:

PUT /api/v1/quiz_submissions/:quiz_submission_id/questions/:id/flag

Parameters:

validation_token (str) – (Optional) The unique validation token for the quiz submission. If one is not provided, canvasapi will attempt to use self.validation_token.

Returns:

True if the question was successfully flagged, False otherwise.

Return type:

bool

unflag(validation_token=None, **kwargs)

Remove a previously set flag on a quiz question.

Calls:

PUT /api/v1/quiz_submissions/:quiz_submission_id/questions/:id/unflag

Parameters:

validation_token (str) – (Optional) The unique validation token for the quiz submission. If one is not provided, canvasapi will attempt to use self.validation_token.

Returns:

True if the question was successfully unflagged, False otherwise.

Return type:

bool