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!
Hello All,
I wanted to see if anyone knew of an API that would allow me to assign a paper/quiz/discussion to a specific section in a course instead of defaulting to everyone? I have looked at the docs and I cannot seem to find a way to do this via API. It seems to be that if this is in the GUI there should be an API endpoint but I cannot find it. I appreciate the help.
Jason
Solved! Go to Solution.
Jason,
I ran a python script last year to create overrides for a bunch of assignments that had certain characters in its title. We replicated a discussion assignment 80+ times. We appended a "(Section Name)" to each replicated assignment and then set overrides so each section would only see their assignment. Here are excerpts from it to help you out. (Sorry for the formatting, I couldn't figure out how to get the code to display properly) It ran last year, but you'll want to test it since overrides are in beta.
import csv, json, sys, requests, time, getopt
from prod_settings import base_url, api_url, token, account_id
#First I created a dictionary of my sections
# build dictionary of SIS_ID:Canvas_ID.
response = requests.get(api_url + '/courses/' + target_course_id + '/sections/', headers = {'Authorization': 'Bearer ' + '%s' % token})
more = 1
sectionList = {}
while more ==1:
data = response.json()
print(data)
print('Dict creation')
for d in data:
#Since I'm using the section names, I had our sis id paired with the Canvas ID for the section
sectionList[d['sis_section_id']] = d['id']
# Just to make sure the ids are what I expect
print(d['sis_section_id'],' : ',sectionList[d['sis_section_id']])
if 'next' in response.links:
response = requests.get(response.links["next"]["url"],headers = {'Authorization': 'Bearer ' + '%s' % token})
else:
more = -1
Then later on I go through my assignments looking for certain characters in the title, if they exist, I override them. The section they go to is in the assignment title to make it easier for the instructors to access the right assignments.
# Create Assignment_Overrides
response = requests.get(api_url + '/courses/' + target_course_id + '/assignments/', headers = {'Authorization': 'Bearer ' + '%s' % token})
more = 1
while more == 1:
data = response.json()
for d in data:
s = d['name']
#Grab the section name
s = s[-17:-1]
print(d['id'],d['name'],' ',s)
if s.startswith('s_1178'):
print('creating override')
# find Section ID based on Section name
# Set Override
print('config: ',sectionList[s],'-Due-',d['due_at'],'-unlock-',d['unlock_at'],'-lock-',d['lock_at'])
payload_override = {
'assignment_override[course_section_id]':sectionList[s],
'assignment_override[due_at]':d['due_at'],
'assignment_override[unlock_at]':d['unlock_at'],
'assignment_override[lock_at]':d['lock_at']
}
override_response = requests.post(api_url + '/courses/' + course_id + '/assignments/' + str(d['id']) + '/overrides/' , headers = {'Authorization': 'Bearer ' + '%s' % token}, params = payload_override)
#Remove "Everyone" and publish the assignment
payload = {
'assignment[only_visible_to_overrides]':'True',
'assignment[published]':'True'
}
override_response = requests.put(api_url + '/courses/' + target_course_id + '/assignments/' + str(d['id']), headers = {'Authorization': 'Bearer ' + '%s' % token}, params = payload)
else:
print('Not creating for ',s)
if 'next' in response.links:
response = requests.get(response.links["next"]["url"],headers = {'Authorization': 'Bearer ' + '%s' % token})
else:
more = -1
Hope this helps,
Ryan
For assignment, here are the API endpoints (Assignment Overrides - Canvas LMS REST API Documentation ). For discussion and quiz, you may need to create discussion/quiz as an assignment. This may not be the best practice, so just for your reference.
Jason,
I ran a python script last year to create overrides for a bunch of assignments that had certain characters in its title. We replicated a discussion assignment 80+ times. We appended a "(Section Name)" to each replicated assignment and then set overrides so each section would only see their assignment. Here are excerpts from it to help you out. (Sorry for the formatting, I couldn't figure out how to get the code to display properly) It ran last year, but you'll want to test it since overrides are in beta.
import csv, json, sys, requests, time, getopt
from prod_settings import base_url, api_url, token, account_id
#First I created a dictionary of my sections
# build dictionary of SIS_ID:Canvas_ID.
response = requests.get(api_url + '/courses/' + target_course_id + '/sections/', headers = {'Authorization': 'Bearer ' + '%s' % token})
more = 1
sectionList = {}
while more ==1:
data = response.json()
print(data)
print('Dict creation')
for d in data:
#Since I'm using the section names, I had our sis id paired with the Canvas ID for the section
sectionList[d['sis_section_id']] = d['id']
# Just to make sure the ids are what I expect
print(d['sis_section_id'],' : ',sectionList[d['sis_section_id']])
if 'next' in response.links:
response = requests.get(response.links["next"]["url"],headers = {'Authorization': 'Bearer ' + '%s' % token})
else:
more = -1
Then later on I go through my assignments looking for certain characters in the title, if they exist, I override them. The section they go to is in the assignment title to make it easier for the instructors to access the right assignments.
# Create Assignment_Overrides
response = requests.get(api_url + '/courses/' + target_course_id + '/assignments/', headers = {'Authorization': 'Bearer ' + '%s' % token})
more = 1
while more == 1:
data = response.json()
for d in data:
s = d['name']
#Grab the section name
s = s[-17:-1]
print(d['id'],d['name'],' ',s)
if s.startswith('s_1178'):
print('creating override')
# find Section ID based on Section name
# Set Override
print('config: ',sectionList[s],'-Due-',d['due_at'],'-unlock-',d['unlock_at'],'-lock-',d['lock_at'])
payload_override = {
'assignment_override[course_section_id]':sectionList[s],
'assignment_override[due_at]':d['due_at'],
'assignment_override[unlock_at]':d['unlock_at'],
'assignment_override[lock_at]':d['lock_at']
}
override_response = requests.post(api_url + '/courses/' + course_id + '/assignments/' + str(d['id']) + '/overrides/' , headers = {'Authorization': 'Bearer ' + '%s' % token}, params = payload_override)
#Remove "Everyone" and publish the assignment
payload = {
'assignment[only_visible_to_overrides]':'True',
'assignment[published]':'True'
}
override_response = requests.put(api_url + '/courses/' + target_course_id + '/assignments/' + str(d['id']), headers = {'Authorization': 'Bearer ' + '%s' % token}, params = payload)
else:
print('Not creating for ',s)
if 'next' in response.links:
response = requests.get(response.links["next"]["url"],headers = {'Authorization': 'Bearer ' + '%s' % token})
else:
more = -1
Hope this helps,
Ryan
@gladysie ,
Brilliant! The assignment visibility piece is what I was missing. Thanks for the assist.
Regards,
Jason
To interact with Panda Bot in the Instructure Community, you need to sign up or log in:
Sign In