Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
I am using the Canvas API to create folders and subfolders of courses that have been offered at my institution in the past. I used a simple Python script to do this and when I executed the code through my terminal, it reflected on the Canvas site.
I tried to use this request to create a new folder with subfolders, but nothing was listed in my terminal (I had added lines to my script that would allow me to see which courses were added to the files and the JSON). I am wondering if I did something wrong within my code, or if I had hit the rate limit.
I'm not a python expert, but I think spacing is important. I think I can follow what you're trying to do, but when editing a message here in the Community, there are three dots at the end of the editor toolbar. Those expand a second line where there is a </> button to insert code. You can select Python and it will even do highlighting. It makes it a lot easier to follow code.
As for the rate limit, as long as you're making synchronous calls, you won't hit it. Again, I'm not the python expert, but from what I've seen is that it is synchronous and one request must finish before the next. JavaScript, on the other hand, makes asynchronous calls and you definitely have to watch out to make sure you don't exceed the rate limit.
One thing to do when testing is test it with a smaller subset. I'll use JavaScript language since that's what I'm familiar with, but if my spring_2024_courses is an array of 500 courses, I might try hard-coding it with just one for testing purposes. Make sure it works there before you move on to the full array.
Since I cannot tell where your indentation is, it looks like you have a course (just one) that has a folder called "Spring 2024" in it, and that you are trying to make a bunch of folders under that course.
Is this the kind of structure you're looking for -- again -- all within the same course?
The reason I keep repeating the "same course" part is because your course_id isn't changing between requests.
When I tried making a request using a REST client with a JSON request of
{"name":"Math 113", "parent_folder_path":"Spring 2024"}
it worked as expected but gave me a response code of 200, not 201. That would explain why it's not printing anything in the terminal.
When I repeated that with the name of "Engl 101", it worked as well.
If the issue is that nothing is printing in the terminal, that's due to the status code.
If the files aren't showing up in Canvas, then I would double check the value of course_id and make sure the requests are being sent to the proper course. You may have just created a bunch of folders in the wrong place.
To participate in the Instructure Community, you need to sign up or log in:
Sign In