Question banks - What can be done without an API?

maguire
Community Champion
2
1113

A couple of days ago I decided to re-examine an issue that has annoyed me several times, the lack of a Question Bank API. The process began with some postings to followup the question raised by 10618071 in https://community.canvaslms.com/thread/14766-where-is-the-question-bank-api

This lead to some Tampermoney scripts (such as https://kth.instructure.com/courses/11/pages/using-tampermonkey-to-add-question-banks-v2) that enabled me to add question banks. This success lead to a desire for further automation and this lead me to investigate the combination of Puppeteer (https://pptr.dev/) and Node to run Javascripts to create a question bank- the first result was Using Puppeteer to insert new question bank: Chip sandbox. After seeing what Puppeteer could do I expanded upon the program to have a program that would not only let me add question banks but would also output a JSON file of the resulting set of question banks (which of course could then be used with the Canvas API to insert questions into question banks!). The resulting program is documented at https://kth.instructure.com/courses/11/pages/using-puppeteer-to-create-new-question-banks-and-get-js...

Some obvious programs that could be derived from this last script would be:

  • to read a JSON file or CSV file that contains a list of question banks that one wants to create along with the course_id to create them in
  • a program to simply output the JSON for the existing question banks in a course

Of course, the real solution is to add a Question bank API. Meanwhile, quite a lot can be done despite the lack of such an API.

Once again I wish to thank  @James  and the many others who have provided examples of JavaScript and Puppeteer scripts. I still do not know how to use Puppeteer (well) and lack confidence in navigating DOM structures (especially of pages that have elements that lack IDs or that dynamically modify the Javascript on a page).

2 Comments
maguire
Community Champion

For those who find Puppeteer useful, I found that it is possible to have one script that logins into Canvas, saves the cookies, and quits (closing the browser window). Then another script can be run that loads these cookies and then interactions with Canvas without having to log in again. Details at https://kth.instructure.com/courses/11/pages/running-a-second-puppeteer-script-using-the-same-sessio... .

maguire
Community Champion

For more fun with Puppeteer see my comment at https://community.canvaslms.com/message/108347-searching-for-users

This latest Puppeteer code uses Promises (to deal with parts of the page that appear dynamically) and two supporting programs that walk two tree-structured sets of dynamically loaded Javascript supplied data, so that when the main program runs - it knows how to go directly to the correct place in the tree.