Download annotated submissions via API

Jump to solution
Community Novice

Hi - I am trying to figure out a way to bulk download annotated submissions from Canvas. What I would like to be able to do is to download all annotated submissions for a particular student across a number of Canvas courses. This is that the student's tutor can look over the portfolio of marked and annotated submission for their tutee from time to time without having to go through all relevant courses. For practical reasons, I'd like tutors to actually get the files rather than a link to the file preview in docviewer (which shows the submissions).

I think the above cannot be done via the API. Using the submissions API (in the attachments), I can get the URL of the file (without annotations) or the preview url, which brings up the docviewer. The preview url seems to be an API call that gets redirected to a canvasdocs session. On that page, one can see the document with annotations, and there is a button on the top left that allows the viewer to download the annotated pdf.

Here is the question: is there a creative way of automatically download that pdf? (I am guessing there is no standard way to do this).

I looked at the source of the docviewer page and it seems that the download button calls some sort of javascript code. I guess the script produces a pdf of the submission + annotations and serves it up as a file to download...but I do not know and cannot think of a way of doing this in a batch way so that I can download all files...

Any ideas?



2 Solutions
Community Novice

I thought I submitted it from the developer community page and assumed it would appear in the group...thanks!

I have 'followed' the group...


View solution in original post

Community Champion

 @adamwarecx ,

I found out how to download the file without loading the redirected page or running any JavaScript. I was able to download the file from within the Advanced Rest Client without loading a browser, which means that you can do it without having a headless browser.

  1. GET the submission information (API call)
  2. GET the preview URL (API call). Do not automatically follow the redirection, you need the location from it.
  3. Obtain the redirect location, but don't call it. Let's call most of it location so that it looks like location/view?theme=dark
  4. Replace the location/view?theme=dark with location/annotated.pdf and then POST to that address. No payload is necessary.
  5. GET location/annotated.pdf/is_ready until it returns { ready:true }
  6. GET location/annotated.pdf and save your file

Step 5 didn't take very long, but I was running it on a very small document with few annotations.

View solution in original post