Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
Hi all,
I wrote a pretty rudimentary Python script that finds a course's root folder ID then upload files to it via the ZIP File Importer API. I noticed that the "https://montclair.instructure.com/api/v1/courses/:course_id/folders" API sometimes responds with nothing, so the script will wait a bit and try the request again if that happens. I noticed that trying again isn't so successful at times until I access the course via my browser. For some reason, once I access the course through the browser, Canvas suddenly starts passing back the expected response through the API. Is there a reason why accessing the course via my browser would kickstart the Canvas API?
Thanks in advance!
Patrick
This is a shot in the dark and I will offer it since no one has given you anything...
But does the user you are authenticated as have permissions to add files to that course folder? Maybe the event that is triggering the file to be added is some local authentication.
Thanks for reply, Matt! The token I'm using belongs to my admin account, which isn't enrolled as a user in any of the courses, but it does have the appropriate file permissions.
Hi @sciosciap ,
I am going through having a look at some of the early days in the Canvas Developers group, and checking in to see if older enquiries have been answered. I also noticed there hasn’t been any discussion on this question in quite some time.
I am wondering, were you ever able to resolve this? I am hoping I can assume that it is well and truly resolved by now, but if not, please let us know and we can certainly have another look. Alternatively, if have some insights you may be able to share for others that would be awesome too!
I will mark this as assumed answered for the time being, however, by all means please let us know if you still have an outstanding question and we will take a peek!
Cheers,
Stuart
Hi Stuart,
I originally needed this to upload a standard syllabus to multiple courses. I ended up just uploading HTML en masse to multiple courses. Blueprints also replaces what I wanted to do.
If you're interested in the script I was using, please view it below (I am not a programmer so the code is probably terrible). The script would hang on the sleep until I actually visited the page in a browser.
import requests
import time
HEADERS = {'Authorization':'Bearer XXXXXXX'}
#LIST COURSES HERE
li = []
count = 0
for s in li:
z = []
#FIND COURSE FOLDER ID
while z == []:
folderIDAPI = "https://montclair.instructure.com/api/v1/courses/%s/folders" % (s)
payload = {}
r = requests.get(folderIDAPI, headers = HEADERS, data=payload)
z = r.json()
print s
if z == []:
time.sleep (30)
for i in z:
if i['name'] == 'course files':
coursefilesURL = i['id']
print coursefilesURL
#ZIP FILE IMPORT TO COURSE FILES URL
ZIPFileImporter = "https://montclair.instructure.com/api/v1/courses/%s/content_migrations" % (s)
payload = {'migration_type':'zip_file_importer',
'settings[file_url]':'https://www.dropbox.com/', 'settings[folder_id]': coursefilesURL } #I used Dropbox to upload files - this works fine with other Caniverse stuff
r = requests.post(ZIPFileImporter, headers = HEADERS, data=payload)
print s + " SUCCESS"
count += 1
print count
time.sleep(2)
To participate in the Instructure Community, you need to sign up or log in:
Sign In