Register for InstructureCon25 • Passes include access to all sessions, the expo hall, entertainment and networking events, meals, and extraterrestrial encounters.
Found this content helpful? Log in or sign up to leave a like!
I have an assignment (a graded discussion topic) that is assigned to different sections with different due dates for each section. It is not assigned to all students, only by section.
When I query the API for the JSON entry for this assignment:
1) It has a listed due date which is one of the due dates assigned to one of the sections
2) I can't find anywhere in the JSON entry where it lists who the assignment is assigned to and what the due date for that group of students is. 'has_overrides' is True, but I can't find those overrides listed anywhere.
Can anyone help me with this? JSON entry is below if anyone needs it.
{
'id': 7267939,
'description': '<div class="entry-content ">\n<div class="discussion-section message_wrapper">\n<div class="message user_content enhanced" data-bind="message">\n<p><span>What role do microbes play in the human body? Why do we study them? What percentage of microbes do you think cause disease in humans?</span></p>\n</div>\n</div>\n</div>\n<div id="discussion-toolbar" class="toolbarView unsubscribed"></div>',
'due_at': '2024-08-29T22:50:00Z',
'unlock_at': '2024-08-29T01:00:00Z',
'lock_at': '2024-08-29T22:50:00Z',
'points_possible': 1.0,
'grading_type': 'points',
'assignment_group_id': 1885435,
'grading_standard_id': None,
'created_at': '2024-08-05T18:11:01Z',
'updated_at': '2024-08-05T23:11:00Z',
'peer_reviews': False,
'automatic_peer_reviews': False,
'position': 3,
'grade_group_students_individually': False,
'anonymous_peer_reviews': False,
'group_category_id': None,
'post_to_sis': False,
'moderated_grading': False,
'omit_from_final_grade': False,
'intra_group_peer_reviews': False,
'anonymous_instructor_annotations': False,
'anonymous_grading': False,
'graders_anonymous_to_graders': False,
'grader_count': 0,
'grader_comments_visible_to_graders': True,
'final_grader_id': None,
'grader_names_visible_to_final_grader': True,
'allowed_attempts': -1,
'annotatable_attachment_id': None,
'hide_in_gradebook': False,
'secure_params': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsdGlfYXNzaWdubWVudF9pZCI6ImMxZGFjZmJmLTk0YWItNGFlNi1iZDZjLWQ4Njk2ZGJlNjRhMCIsImx0aV9hc3NpZ25tZW50X2Rlc2NyaXB0aW9uIjoiXHUwMDNjZGl2IGNsYXNzPVwiZW50cnktY29udGVudCBcIlx1MDAzZVxuXHUwMDNjZGl2IGNsYXNzPVwiZGlzY3Vzc2lvbi1zZWN0aW9uIG1lc3NhZ2Vfd3JhcHBlclwiXHUwMDNlXG5cdTAwM2NkaXYgY2xhc3M9XCJtZXNzYWdlIHVzZXJfY29udGVudCBlbmhhbmNlZFwiIGRhdGEtYmluZD1cIm1lc3NhZ2VcIlx1MDAzZVxuXHUwMDNjcFx1MDAzZVx1MDAzY3NwYW5cdTAwM2VXaGF0IHJvbGUgZG8gbWljcm9iZXMgcGxheSBpbiB0aGUgaHVtYW4gYm9keT8gV2h5IGRvIHdlIHN0dWR5IHRoZW0_IFdoYXQgcGVyY2VudGFnZSBvZiBtaWNyb2JlcyBkbyB5b3UgdGhpbmsgY2F1c2UgZGlzZWFzZSBpbiBodW1hbnM_XHUwMDNjL3NwYW5cdTAwM2VcdTAwM2MvcFx1MDAzZVxuXHUwMDNjL2Rpdlx1MDAzZVxuXHUwMDNjL2Rpdlx1MDAzZVxuXHUwMDNjL2Rpdlx1MDAzZVxuXHUwMDNjZGl2IGlkPVwiZGlzY3Vzc2lvbi10b29sYmFyXCIgY2xhc3M9XCJ0b29sYmFyVmlldyB1bnN1YnNjcmliZWRcIlx1MDAzZVx1MDAzYy9kaXZcdTAwM2UifQ.UFJmY20zQ5IEPZ5KsLUQGZJyQ7v83GDjOSY3xvsFawI',
'lti_context_id': 'c1dacfbf-94ab-4ae6-bd6c-d8696dbe64a0',
'course_id': 1389750,
'name': 'Week 1 - DQ1',
'submission_types': ['discussion_topic'],
'has_submitted_submissions': False,
'due_date_required': False,
'max_name_length': 255,
'in_closed_grading_period': False,
'graded_submissions_exist': True,
'is_quiz_assignment': False,
'can_duplicate': True,
'original_course_id': None,
'original_assignment_id': None,
'original_lti_resource_link_id': None,
'original_assignment_name': None,
'original_quiz_id': None,
'workflow_state': 'published',
'important_dates': False,
'muted': False,
'html_url': 'https://csn.instructure.com/courses/1389750/assignments/7267939',
'has_overrides': True,
'needs_grading_count': 0,
'sis_assignment_id': None,
'integration_id': None,
'integration_data': {},
'discussion_topic': {
'id': 4484626,
'title': 'Week 1 - DQ1',
'last_reply_at': '2024-08-05T23:10:59Z',
'created_at': '2024-08-05T18:11:01Z',
'delayed_post_at': None,
'posted_at': '2024-08-05T23:10:59Z',
'assignment_id': 7267939,
'root_topic_id': None,
'position': None,
'podcast_has_student_posts': False,
'discussion_type': 'side_comment',
'lock_at': None,
'allow_rating': False,
'only_graders_can_rate': False,
'sort_by_rating': False,
'is_section_specific': False,
'anonymous_state': None,
'summary_enabled': False,
'user_name': None,
'discussion_subentry_count': 1,
'permissions': {
'attach': True,
'update': True,
'reply': True,
'delete': True,
'manage_assign_to': True
},
'require_initial_post': True,
'user_can_see_posts': True,
'podcast_url': None,
'read_state': 'read',
'unread_count': 0,
'subscribed': True,
'attachments': [],
'published': True,
'can_unpublish': True,
'locked': False,
'can_lock': False,
'comments_disabled': False,
'author': {},
'html_url': 'https://csn.instructure.com/courses/1389750/discussion_topics/4484626',
'url': 'https://csn.instructure.com/courses/1389750/discussion_topics/4484626',
'pinned': False,
'group_category_id': None,
'can_group': True,
'topic_children': [],
'group_topic_children': [],
'locked_for_user': False,
'message': '<div class="entry-content ">\n<div class="discussion-section message_wrapper">\n<div class="message user_content enhanced" data-bind="message">\n<p><span>What role do microbes play in the human body? Why do we study them? What percentage of microbes do you think cause disease in humans?</span></p>\n</div>\n</div>\n</div>\n<div id="discussion-toolbar" class="toolbarView unsubscribed"></div>',
'todo_date': None,
'is_announcement': False
},
'published': True,
'unpublishable': True,
'only_visible_to_overrides': True,
'visible_to_everyone': False,
'locked_for_user': False,
'submissions_download_url': 'https://csn.instructure.com/courses/1389750/assignments/7267939/submissions?zip=1',
'post_manually': False,
'anonymize_students': False,
'require_lockdown_browser': False,
'restrict_quantitative_data': False
}
Solved! Go to Solution.
Hi @JoshuaStomel,
Since you're sending the data as json (which is normally what I do), and looking at the API spec, I think you need to add your info into an assignment override main dictionary. Try:
override = {'assignment_override':{
'course_section_id': 1555035,
'id': 138276,
'assignment_id': 7267945,
'title': 'BIOL 251 - 3001 FALL 2024',
'due_at': '2024-09-03T02:20:00Z',
'unlock_at': '2024-09-03T01:00:00Z',
'lock_at': '2024-08-29T02:20:00Z',
'all_day': False,
'all_day_date': '2024-09-03',
'unassign_item': False
}}
Let us know if this works
-Chris
Hi @JoshuaStomel,
Assuming you're using the list assignments or get an assignment API for this, you should be able to add "include[]=overrides" to your API query URL to have the override info included in the response. Your API URL would be something like this: "http://domain.instructure.com/api/v1/courses/:course_id/assignments?include[]=overrides" or "http://domain.instructure.com/api/v1/courses/:course_id/assignment?/:id/include[]=overrides".
Let us know if that small tweak works for you.
-Chris
I'm actually grabbing all of the assignments and then iterating through them for the one with the name that I'm looking for.
I'm grabbing it in python with
url = f'{API_URL}/courses/{course_id}/assignments'
while url:
response = requests.get(url, headers=headers)
and then iterating through assignments looking for the entry that matches an inputed assignment name. Is there a way to grab a single assignment in python?
Hi @JoshuaStomel,
Yes, you can get a single assignment via the API, but that call requires you to know the numeric canvas_id of the assignment, not something like the name, so it may not be very useful for you.
You can use the list assignments endpoint as you already and add a "search_term" parameter to narrow down the results based on the title though. If you're looking for multiple assignments though, it may be more efficient to just get the entire list first, then do all of your iterations looking for things. This brings me to another thing you may need to address in your code, which is pagination... By default the Canvas API will only return 10 results for most list calls. You can add a parameter to up that to 100, though the best way to handle pagination universally is to look at the headers to determine if there are more pages of results to fetch after each call. You may already be doing this, but it's hard to know for sure from the snippets you posted, so I thought I'd mention this here.
Hope this info helps!
-Chris
I got this part figured out. You were right, I had to add ?include[]=overrides to my request.
Now I'm stuck trying to create an override. Here's what I'm doing (in short)
override =
override = {
'course_section_id': 1555035,
'id': 138276,
'assignment_id': 7267945,
'title': 'BIOL 251 - 3001 FALL 2024',
'due_at': '2024-09-03T02:20:00Z',
'unlock_at': '2024-09-03T01:00:00Z',
'lock_at': '2024-08-29T02:20:00Z',
'all_day': False,
'all_day_date': '2024-09-03',
'unassign_item': False
}
response = requests.post(f'{API_URL}/courses/{course_id}/assignments/{assignment_id}/overrides', headers=headers, json=override)
and I get back Error: 400 - {"errors":["one of student_ids, group_id, or course_section_id is required"]}
There is a course_section_id specified in the data structure I am passing it, so I'm not sure what it wants?
Hi @JoshuaStomel,
Since you're sending the data as json (which is normally what I do), and looking at the API spec, I think you need to add your info into an assignment override main dictionary. Try:
override = {'assignment_override':{
'course_section_id': 1555035,
'id': 138276,
'assignment_id': 7267945,
'title': 'BIOL 251 - 3001 FALL 2024',
'due_at': '2024-09-03T02:20:00Z',
'unlock_at': '2024-09-03T01:00:00Z',
'lock_at': '2024-08-29T02:20:00Z',
'all_day': False,
'all_day_date': '2024-09-03',
'unassign_item': False
}}
Let us know if this works
-Chris
I found some similar advice on this thread (https://community.canvaslms.com/t5/Canvas-Developers-Group/Section-Assignment/td-p/122415)
It worked when I changed my data structure to this:
'assignment_override[id]': None,
'assignment_override[assignment_id]': assignment_id,
'assignment_override[title]': 'BIOL 251 - 3001 FALL 2024',
'assignment_override[due_at]': '2024-09-03T02:20:00Z',
'assignment_override[unlock_at]': '2024-09-03T01:00:00Z',
'assignment_override[lock_at]': '2024-09-03T02:20:00Z',
'assignment_override[course_section_id]': section_map.get('BIOL 251 - 3001 FALL 2024'),
'assignment_override[all_day]': False,
'assignment_override[all_day_date]': '2024-09-03',
'assignment_override[unassign_item]': False
I guess I'm putting the assignment_override on every item. Your solution looks more elegant, but this seems to get the job done. Oh yeah, and I had to change the requests.post from json=override to params=override. Not sure why, but it worked and I've got my script working. Thanks! I'm not much of a coder, I know enough to get into trouble but I don't actually understand what I'm doing most of the time. I've been using chatGPT to help me write most of the actual code, and it isn't great at telling me why it tried to do things the way it did.
To interact with Panda Bot in the Instructure Community, you need to sign up or log in:
Sign In