cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Surveyor

Getting Quiz/Section mapping using REST API

For assignments I can get overrides to figure out which Sections they are assigned to. But how do I do that for Quizzes? There doesn't seem to be an override and I can't map a Quiz object to something else that gives me Section information.

Labels (2)
Tags (2)
14 Replies
Highlighted
Navigator

martinv@andrew.cmu.edu 

I'm not sure if I am missing something.

The overrides for quizzes are found under the associated assignment for the quiz. If you have the assignment overrides, you have the quiz overrides.

For example, let's say that I'm editing a quiz with this pathname: /courses/2687822/quizzes/6432609/edit and it looks like this inside Canvas.

347003_pastedImage_2.png

This quiz is only available to 10 students (I have different versions of my final) and split it up.

If I use the API to get the quiz information, I get a JSON object (I'm only showing parts of it here)

GET /api/v1/courses/2687822/quizzes/6432609

{
"id":6432609,
"title":"Final Challenge",
"quiz_type":"assignment",
"all_dates":[
{
"id":2336822,
"due_at":"2020-05-13T04:59:59Z",
"unlock_at":"2020-05-11T05:00:00Z",
"lock_at":"2020-05-14T04:59:59Z",
"title":"10 students"
}
],
"assignment_id":26647463,
}

It shows me that there is an override inside the all_dates property, but not who it is assigned to.

The thing that I need is the assignment_id 26647463.

I get the single assignment from the API with include[]=overrides.

GET /api/v1/courses/2687822/assignments/26647463?include[]=overrides

This includes (again, I've stripped some out) a list of the overrides.

347004_pastedImage_3.png

Mine are showing up as "student_ids" because it's assigned to individual students. You would have a different property there if it is for a section.

Highlighted

@James ,

This is great, but is there a way to create or edit quiz overrides from the canvas API?  I have successfully done so with assignments (I can create/edit/delete overrides for assignments, but not quizzes!)

0 Kudos
Highlighted

@jsagisi

When you save assignment overrides for a quiz through the web interface, it doesn't use the API. It uses an internal route and has a property quiz.assignment_overrides[]

Overrides aren't handled at the quiz level, though. They're handled at the assignment level. The internal call takes assignment_overrides[] and passes it on to the assignments controller to AssignmentOverridesController to actually handle the override portion of it (I'm speaking without actually looking at the source code, but the principle is correct).

If you want to create an override through the API, you don't override the quiz to assign it to individual students, you override the assignment that corresponds to the quiz.

You query the quiz to get the assignment_id and then you create the corresponding assignment like it was any other assignment. 

I did test this to confirm this works for a quiz.

Highlighted

@James ,  brilliant explanation.  Thank you for the insight!  I actually am developing a tool based on your lesson manager tool that manages lessons/quizzes and homeworks for our institution.  We have a weird schedule where sections are based on Day 1/Day2 labels.  These days are almost completely arbitrary throughout the semester instead of a normal MWF and TR deal.  I'm hoping it would help instructors in other institutions as well with a nonstandard section calendar.

Would you mind posting a verified snipped with your code?  I have the following but it always returns a null (verified by using ui.alert(JSON.stringify(result)). The CanvasAPI string is part of the assignments API:

 

  //CREATE ASSIGNMENT OVERRIDE GIVEN QUIZ ID
  result = canvasAPI('POST /api/v1/courses/:course_id/assignments/:assignment_id/overrides',{ 
    ':course_id': 2247293, // Course Id
    ':id':5812067,         // Problem Set 1 Quiz Id
    'assignment_override[course_section_id]': 2408773, // Section 'H1'
    'assignment_override[due_at]': new Date('2020-11-19T03:59:59Z'),
  }
                    );

 

 

 

 

 

This quiz already has some overrides.  I wanted to add one for a section called 'H1':

 

 

 

 

"all_dates": [
{
"id": 858389,
"due_at": "2020-08-19T03:59:59Z",
"unlock_at": "2020-08-10T04:00:00Z",
"lock_at": "2020-08-29T03:59:59Z",
"title": "G1",
"set_type": "CourseSection",
"set_id": 2408772
},
{
"id": 858390,
"due_at": "2020-08-20T03:59:59Z",
"unlock_at": "2020-08-03T04:00:00Z",
"lock_at": "2020-08-30T03:59:59Z",
"title": "G2",
"set_type": "CourseSection",
"set_id": 2408774
}
],

 

 

 

 

 

The full quiz (Problem Set) JSON is below:

 

 

 

 

{
"id": 5812067,
"title": "Probelm Set 1",
"html_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067",
"mobile_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067?force_user=1&persist_headless=1",
"description": "<p>You must provide documentation for each problem.  See <a class=\"instructure_file_link instructure_scribd_file\" title=\"Documentation_Example_Citations.txt\" href=\"https://canvas.instructure.com/courses/2247293/files/103970667/download?wrap=1\" data-api-endpoint=\"https://canvas.instructure.com/api/v1/courses/2247293/files/103970667\" data-api-returntype=\"File\">example citations</a> for proper guidance (also found in <a title=\"Course Resources\" href=\"https://canvas.instructure.com/courses/2247293/pages/course-resources#https:\" data-api-endpoint=\"https://canvas.instructure.com/api/v1/courses/2247293/pages/course-resources%23https:\" data-api-returntype=\"Page\">Course Resources</a>).</p>",
"quiz_type": "assignment",
"time_limit": null,
"timer_autosubmit_disabled": false,
"shuffle_answers": false,
"show_correct_answers": false,
"scoring_policy": "keep_highest",
"allowed_attempts": -1,
"one_question_at_a_time": false,
"question_count": 8,
"points_possible": 40,
"cant_go_back": false,
"access_code": null,
"ip_filter": null,
"due_at": "2020-07-29T03:59:00Z",
"lock_at": "2020-07-29T03:59:00Z",
"unlock_at": "2020-06-03T04:00:00Z",
"published": true,
"unpublishable": true,
"locked_for_user": true,
"lock_info": {
"missing_permission": "participate_as_student",
"asset_string": "quizzes:quiz_5812067"
},
"lock_explanation": "This quiz is currently locked.",
"hide_results": null,
"show_correct_answers_at": null,
"hide_correct_answers_at": null,
"all_dates": [
{
"id": 858389,
"due_at": "2020-08-19T03:59:59Z",
"unlock_at": "2020-08-10T04:00:00Z",
"lock_at": "2020-08-29T03:59:59Z",
"title": "G1",
"set_type": "CourseSection",
"set_id": 2408772
},
{
"id": 858390,
"due_at": "2020-08-20T03:59:59Z",
"unlock_at": "2020-08-03T04:00:00Z",
"lock_at": "2020-08-30T03:59:59Z",
"title": "G2",
"set_type": "CourseSection",
"set_id": 2408774
}
],
"can_unpublish": true,
"can_update": true,
"require_lockdown_browser": false,
"require_lockdown_browser_for_results": false,
"require_lockdown_browser_monitor": false,
"lockdown_browser_monitor_data": "",
"speed_grader_url": "https://canvas.instructure.com/courses/2247293/gradebook/speed_grader?assignment_id=16874595",
"permissions": {
"manage": true,
"read": true,
"update": true,
"create": true,
"submit": true,
"preview": true,
"delete": true,
"read_statistics": true,
"grade": true,
"review_grades": true,
"view_answer_audits": false
},
"quiz_reports_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/reports",
"quiz_statistics_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/statistics",
"message_students_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/submission_users/message",
"section_count": 5,
"quiz_submission_versions_html_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067/submission_versions",
"assignment_id": 16874595,
"one_time_results": false,
"only_visible_to_overrides": true,
"assignment_group_id": 3191775,
"show_correct_answers_last_attempt": false,
"version_number": 6,
"has_access_code": false,
"post_to_sis": false,
},

 

 

 

 

 

Tags (1)
0 Kudos
Highlighted

@James ,

Would you be able to post the snippet that you use according to what you developed in your google sheets tool?

Not sure what happened to my original post, but brilliant explanation!  I am writing a tool similar to your page management tool that manages calendar events/quizzes/assignments and applies assignments by sections.  My institution uses a Day 1/Day 2 method instead of a standard M-W-F/T-R method, and the Day 1 and Day 2's are almost completely arbitrary.  I'm looking to publish it so that many instructors in my institution can leverage it as well as other in institutions with seemingly random section days.

I was able to modify and delete assignments using the Assignments API, but when I apply it to quizzes it seems to return a null.   I have the following.  The CanvasAPI call comes from the Assignments API:

 

  //CREATE ASSIGNMENT OVERRIDE GIVEN QUIZ ID
  result = canvasAPI('POST /api/v1/courses/:course_id/assignments/:assignment_id/overrides',{ 
    ':course_id': 2247293, // Course Id
    ':id':5812067,         // Problem Set 1 Quiz Id
    'assignment_override[course_section_id]': 2408773, // Section 'H2'
    'assignment_override[due_at]': new Date('2020-11-19T03:59:59Z'),
  }
                    );

 

As applied to a quiz that already has an existing override for sections G1 and H1.  In the above, I am trying to add section H2.  Here is a snippet of showing the Quiz object as it contains the override:

 

 

"all_dates": [
{
"id": 858389,
"due_at": "2020-08-19T03:59:59Z",
"unlock_at": "2020-08-10T04:00:00Z",
"lock_at": "2020-08-29T03:59:59Z",
"title": "G1",
"set_type": "CourseSection",
"set_id": 2408772
},
{
"id": 858390,
"due_at": "2020-08-20T03:59:59Z",
"unlock_at": "2020-08-03T04:00:00Z",
"lock_at": "2020-08-30T03:59:59Z",
"title": "G2",
"set_type": "CourseSection",
"set_id": 2408774
}
],

 

And here is the full Quiz Object:

 

{
"id": 5812067,
"title": "Probelm Set 1",
"html_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067",
"mobile_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067?force_user=1&persist_headless=1",
"description": "<p>You must provide documentation for each problem.  See <a class=\"instructure_file_link instructure_scribd_file\" title=\"Documentation_Example_Citations.txt\" href=\"https://canvas.instructure.com/courses/2247293/files/103970667/download?wrap=1\" data-api-endpoint=\"https://canvas.instructure.com/api/v1/courses/2247293/files/103970667\" data-api-returntype=\"File\">example citations</a> for proper guidance (also found in <a title=\"Course Resources\" href=\"https://canvas.instructure.com/courses/2247293/pages/course-resources#https:\" data-api-endpoint=\"https://canvas.instructure.com/api/v1/courses/2247293/pages/course-resources%23https:\" data-api-returntype=\"Page\">Course Resources</a>).</p>",
"quiz_type": "assignment",
"time_limit": null,
"timer_autosubmit_disabled": false,
"shuffle_answers": false,
"show_correct_answers": false,
"scoring_policy": "keep_highest",
"allowed_attempts": -1,
"one_question_at_a_time": false,
"question_count": 8,
"points_possible": 40,
"cant_go_back": false,
"access_code": null,
"ip_filter": null,
"due_at": "2020-07-29T03:59:00Z",
"lock_at": "2020-07-29T03:59:00Z",
"unlock_at": "2020-06-03T04:00:00Z",
"published": true,
"unpublishable": true,
"locked_for_user": true,
"lock_info": {
"missing_permission": "participate_as_student",
"asset_string": "quizzes:quiz_5812067"
},
"lock_explanation": "This quiz is currently locked.",
"hide_results": null,
"show_correct_answers_at": null,
"hide_correct_answers_at": null,
"all_dates": [
{
"id": 858389,
"due_at": "2020-08-19T03:59:59Z",
"unlock_at": "2020-08-10T04:00:00Z",
"lock_at": "2020-08-29T03:59:59Z",
"title": "G1",
"set_type": "CourseSection",
"set_id": 2408772
},
{
"id": 858390,
"due_at": "2020-08-20T03:59:59Z",
"unlock_at": "2020-08-03T04:00:00Z",
"lock_at": "2020-08-30T03:59:59Z",
"title": "G2",
"set_type": "CourseSection",
"set_id": 2408774
}
],
"can_unpublish": true,
"can_update": true,
"require_lockdown_browser": false,
"require_lockdown_browser_for_results": false,
"require_lockdown_browser_monitor": false,
"lockdown_browser_monitor_data": "",
"speed_grader_url": "https://canvas.instructure.com/courses/2247293/gradebook/speed_grader?assignment_id=16874595",
"permissions": {
"manage": true,
"read": true,
"update": true,
"create": true,
"submit": true,
"preview": true,
"delete": true,
"read_statistics": true,
"grade": true,
"review_grades": true,
"view_answer_audits": false
},
"quiz_reports_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/reports",
"quiz_statistics_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/statistics",
"message_students_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/submission_users/message",
"section_count": 5,
"quiz_submission_versions_html_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067/submission_versions",
"assignment_id": 16874595,
"one_time_results": false,
"only_visible_to_overrides": true,
"assignment_group_id": 3191775,
"show_correct_answers_last_attempt": false,
"version_number": 6,
"has_access_code": false,
"post_to_sis": false,
},

 

 

Tags (1)
0 Kudos
Highlighted

@James 

Would you be able to post the snippet that you use according to what you developed in your google sheets tool?

Not sure what happened to my original post, but brilliant explanation!  I am writing a tool similar to your page management tool that manages calendar events/quizzes/assignments and applies assignments by sections.  My institution uses a Day 1/Day 2 method instead of a standard M-W-F/T-R method, and the Day 1 and Day 2's are almost completely arbitrary.  I'm looking to publish it so that many instructors in my institution can leverage it as well as other in institutions with seemingly random section days.

I was able to modify and delete assignments using the Assignments API, but when I apply it to quizzes it seems to return a null.   I have the following.  The CanvasAPI call comes from the Assignments API:

  //CREATE ASSIGNMENT OVERRIDE GIVEN QUIZ ID
  result = canvasAPI('POST /api/v1/courses/:course_id/assignments/:assignment_id/overrides',{ 
    ':course_id': 2247293, // Course Id
    ':id':5812067,         // Problem Set 1 Quiz Id
    'assignment_override[course_section_id]': 2408773, // Section 'H2'
    'assignment_override[due_at]': new Date('2020-11-19T03:59:59Z'),
  }
                    );

 

As applied to a quiz that already has an existing override for sections G1 and H1.  In the above, I am trying to add section H2.  Here is a snippet of showing the Quiz object as it contains the override:

"all_dates": [
{
"id": 858389,
"due_at": "2020-08-19T03:59:59Z",
"unlock_at": "2020-08-10T04:00:00Z",
"lock_at": "2020-08-29T03:59:59Z",
"title": "G1",
"set_type": "CourseSection",
"set_id": 2408772
},
{
"id": 858390,
"due_at": "2020-08-20T03:59:59Z",
"unlock_at": "2020-08-03T04:00:00Z",
"lock_at": "2020-08-30T03:59:59Z",
"title": "G2",
"set_type": "CourseSection",
"set_id": 2408774
}
],

 

And here is the full Quiz Object:

{
"id": 5812067,
"title": "Probelm Set 1",
"html_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067",
"mobile_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067?force_user=1&persist_headless=1",
"description": "<p>You must provide documentation for each problem.  See <a class=\"instructure_file_link instructure_scribd_file\" title=\"Documentation_Example_Citations.txt\" href=\"https://canvas.instructure.com/courses/2247293/files/103970667/download?wrap=1\" data-api-endpoint=\"https://canvas.instructure.com/api/v1/courses/2247293/files/103970667\" data-api-returntype=\"File\">example citations</a> for proper guidance (also found in <a title=\"Course Resources\" href=\"https://canvas.instructure.com/courses/2247293/pages/course-resources#https:\" data-api-endpoint=\"https://canvas.instructure.com/api/v1/courses/2247293/pages/course-resources%23https:\" data-api-returntype=\"Page\">Course Resources</a>).</p>",
"quiz_type": "assignment",
"time_limit": null,
"timer_autosubmit_disabled": false,
"shuffle_answers": false,
"show_correct_answers": false,
"scoring_policy": "keep_highest",
"allowed_attempts": -1,
"one_question_at_a_time": false,
"question_count": 8,
"points_possible": 40,
"cant_go_back": false,
"access_code": null,
"ip_filter": null,
"due_at": "2020-07-29T03:59:00Z",
"lock_at": "2020-07-29T03:59:00Z",
"unlock_at": "2020-06-03T04:00:00Z",
"published": true,
"unpublishable": true,
"locked_for_user": true,
"lock_info": {
"missing_permission": "participate_as_student",
"asset_string": "quizzes:quiz_5812067"
},
"lock_explanation": "This quiz is currently locked.",
"hide_results": null,
"show_correct_answers_at": null,
"hide_correct_answers_at": null,
"all_dates": [
{
"id": 858389,
"due_at": "2020-08-19T03:59:59Z",
"unlock_at": "2020-08-10T04:00:00Z",
"lock_at": "2020-08-29T03:59:59Z",
"title": "G1",
"set_type": "CourseSection",
"set_id": 2408772
},
{
"id": 858390,
"due_at": "2020-08-20T03:59:59Z",
"unlock_at": "2020-08-03T04:00:00Z",
"lock_at": "2020-08-30T03:59:59Z",
"title": "G2",
"set_type": "CourseSection",
"set_id": 2408774
}
],
"can_unpublish": true,
"can_update": true,
"require_lockdown_browser": false,
"require_lockdown_browser_for_results": false,
"require_lockdown_browser_monitor": false,
"lockdown_browser_monitor_data": "",
"speed_grader_url": "https://canvas.instructure.com/courses/2247293/gradebook/speed_grader?assignment_id=16874595",
"permissions": {
"manage": true,
"read": true,
"update": true,
"create": true,
"submit": true,
"preview": true,
"delete": true,
"read_statistics": true,
"grade": true,
"review_grades": true,
"view_answer_audits": false
},
"quiz_reports_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/reports",
"quiz_statistics_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/statistics",
"message_students_url": "https://canvas.instructure.com/api/v1/courses/2247293/quizzes/5812067/submission_users/message",
"section_count": 5,
"quiz_submission_versions_html_url": "https://canvas.instructure.com/courses/2247293/quizzes/5812067/submission_versions",
"assignment_id": 16874595,
"one_time_results": false,
"only_visible_to_overrides": true,
"assignment_group_id": 3191775,
"show_correct_answers_last_attempt": false,
"version_number": 6,
"has_access_code": false,
"post_to_sis": false,
},
Tags (1)
0 Kudos
Highlighted

@James ,

Brilliant insight! I'm not sure why my posts keep bing removed, but are you able to post a snippet of what you used to verify according to your page management tool?  I'm developing/adapting your tool to be able to manage calendar events/quizzes/assignments for institutions where sections are across multiple (seemingly arbitrary) days.  We don't have a standard M-W-F/T-R schedule.  We have a Day1/Day2 schedule, and sometimes Day2 comes before Day1.  

Anyway, I have the below.  For some reason, I always get a returned value of null. The API call is from the Assignments API.  I can't seem to add overrides to either quizzes or assignments using this method.  I would appreciate seeing how you did it.

  //CREATE ASSIGNMENT OVERRIDE GIVEN QUIZ ID
  var result = canvasAPI('POST /api/v1/courses/2247293/assignments/16874608/overrides',{ 
 //   ':course_id': 2247293, // Course Id
 //   ':id':16874608,         // Sensor Lab
    'assignment_override[course_section_id]': 2408773, // Section 'H1'
    'assignment_override[due_at]': new Date('2020-11-19T03:59:59Z'),
  }
        

 

In the above, I am trying to add an override for section H1.  This assignment already has overrides for sections G1 and G2:

[
{
"id": 858732,
"assignment_id": 16874608,
"title": "G1",
"due_at": "2020-08-13T03:59:59Z",
"all_day": true,
"all_day_date": "2020-08-12",
"unlock_at": null,
"lock_at": null,
"course_section_id": 2408772
},
{
"id": 858733,
"assignment_id": 16874608,
"title": "G2",
"due_at": "2020-08-21T03:59:59Z",
"all_day": true,
"all_day_date": "2020-08-20",
"unlock_at": null,
"lock_at": null,
"course_section_id": 2408774
}
]

 

 

Tags (1)
0 Kudos
Highlighted

@James ,

I went ahead and downloaded Insomnia Core REST API explorer and learned how to use it. 

This doesn't make sense to me:

jsagisi_0-1597448338372.png

With the following response:

jsagisi_1-1597448367301.png

It seems to be formatted correctly.  If i change "assignment_override[student_ids][]" to "assignment_override[course_section_id]" it also doesn't work.

0 Kudos
Highlighted

@jsagisi 

I can post snippets, I cannot post images. The new site has a limit of 1000 images and I passed that on the old site.

Are your quizzes for points or are they surveys. I didn't test a survey.

I began with getting the quiz.

GET /api/v1/courses/896851/quizzes/4269816

{
  "id":4269816,
  "quiz_type":"assignment",
  "assignment_id":14605635,
}

 

Now I take that assignment ID and make a post. The student I want to receive the override is 2175488.

POST /api/v1/courses/896851/assignments/14605635/overrides

{
  "assignment_override": {
    "student_ids": [
      2175488
    ],
    "due_at": "2020-08-14T08:00:00Z"
  }
}

 

It comes back with a 201 Created status.

{
  "id":2406878,
  "assignment_id":14605635,
  "title":"1 student",
  "due_at":"2020-08-14T08:00:00Z",
  "all_day":false,
  "all_day_date":"2020-08-14",
  "student_ids":[
    2175488
  ]
}

 

If the student is already in the overrides, then I get a 400 Bad Request status with this message.

{
  "errors":{
    "assignment_override_students":[
      {
        "attribute":"assignment_override_students",
        "type":"taken",
        "message":"already belongs to an assignment override"
      }
    ]
  }
}