cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gchen13
Community Member

Download submissons of assignments using API

Jump to solution

I use Canvas api to access the submissions information, what I am trying to do is to download the submission of student's assignments. I use this format:

/api/v1/courses/CourseId/assignments/AssignmentId/submissions

and get:

{"id":10300000001565999,"body":null,"url":null,"grade":"77","score":77.0,"submitted_at":null,"assignment_id":10300000000046025,"user_id":10300000000020089,"submission_type":null,"workflow_state":"graded","grade_matches_current_submission":true,"graded_at":"2016-11-01T19:19:33Z","grader_id":10300000000024871,"attempt":null,"excused":false,"late":false,"preview_url":"https://canvas.instructure.com/courses/1030~133/assignments/1030~46025/submissions/20089?preview=1\u..."}

This can find individual submission but not include download url. I want to know how to get the exact download url because when I grab url from web and use it in other place, it redirects me to the login page.

Thank you! 

1 Solution

Accepted Solutions
shu14
Community Participant

I got it!!!

I make a stupid mistake. I use "https://canvas.instructure.com/api/v1/courses". I should use "http://mysite.instructure.com/api/v1/courses". "mysite" is my school's name. My problem is solved. Thank you!!!

View solution in original post

18 Replies
Stef_retired
Community Team
Community Team

Hello,  @gchen13 ​! Because of the highly technical nature of this question, I'm sharing it with the Canvas Developers​ and Canvas Admins​ group to bring some experts to the discussion. Also, please note that this question is very similar to one posted earlier today--How to download all students submissions with url --and we try to keep responses unified in a single thread, so I'm going to request that responses be posted here, and I've posted a link to this question in the other thread.

Stef_retired
Community Team
Community Team

For quick reference, here's the text of the other question posted earlier today by  @shu14 ​ (both Shengjie Hu and Jason C are with Stevens Institute of Technology):

I want to download the zip file of all students' assignment submissions. From the API, we get the follow data. But this url is not to a file ("submissions_download_url":"https://[domain]/courses/:coursesID/assignments/:assignmentsID/submissions?zip=1"). When I try to open this page, my API token becomes useless.

So my question is: Who works out that how to download the zip file of all students' assignment submissions. What I should to do?

I am using C++. Thank you.

baxl
Community Contributor

You should see a url that is the downloadable file.  Have you used Postman to make the call?  I highly recommend it. 

gchen13
Community Member

Yes, I use it to make the call, but only find the preview url. The real address seems to be hidden.

tyler_clair
Community Champion

Hi Jason,

In your example the student didn't submit an assignment but was given a grade in the gradebook, so no submission can be downloaded. If the student had a submission there would be an attachments list below the preview_url field, that is where you will find the url to download the assignment, it will have a verifier code in the URL which will allow scripts to download the assignment. Here is an example:

{

    "id": 26610742,

    "body": null,

    "url": null,

    "grade": null,

    "score": null,

    "submitted_at": "2014-01-31T18:39:36Z",

    "assignment_id": 1527806,

    "user_id": 1262968,

    "submission_type": "online_upload",

    "workflow_state": "submitted",

    "grade_matches_current_submission": true,

    "graded_at": null,

    "grader_id": null,

    "attempt": 1,

    "excused": null,

    "late": false,

    "preview_url": "https://usu.instructure.com/courses/267049/assignments/1527806/submissions/1262968?preview=1&version...",

    "attachments": [

      {

        "id": 45338903,

        "folder_id": 1808685,

        "display_name": "Math Application 1 preflight.pdf",

        "filename": "Math+Application+1+preflight.pdf",

        "content-type": "application/pdf",

        "url": "https://usu.instructure.com/files/4533~903/download?download_frd=1&verifier=ppa6A1R8Mf7eqEmG2N0xiojE...",

        "size": 235199,

        "created_at": "2014-01-31T18:39:29Z",

        "updated_at": "2014-08-11T02:26:05Z",

        "unlock_at": null,

        "locked": false,

        "hidden": false,

        "lock_at": null,

        "hidden_for_user": false,

        "thumbnail_url": null,

        "modified_at": "2014-08-11T02:26:05Z",

        "mime_class": "pdf",

        "media_entry_id": null,

        "locked_for_user": false,

        "preview_url": "/api/v1/crocodoc_session?blob=%7B%22user_id%22:10090000000711999,%22attachment_id%22:45338903,%22type%22:%22crocodoc%22%7D&hmac=c7fc977d6cc41ed5cc0a1db310bbfb82f2b63b17"

      }

    ]

  }

Good Luck!

Hi Clair,

Thanks for your reply.

I reviewed the assignment from Canvas and found there was an address, submission could be downloaded from it via browser, but this address requires login info and I am not allowed to call it from postman. Also, I still found nothing below the preview address even though student had uploaded file during submission.

garth
Community Champion

 @gchen13 ​ I have confirmed the results posted by  @tyler_clair ​.

If the student has submitted a document, you should see the "attatchments" array in the json object.

I have tested this in my environment, and verified that the download URL works.

If you are not getting the "attachments" array, verify your parameters to confirm the assignment you are focused on.

tyler_clair
Community Champion

Jason C The URL preview will appear on every submission returned even if the student did not submit an assignment. The preview URL refers to the SpeedGrader in the Canvas UI where the teacher can grade, view, comment on, and even download the assignment. In cases where there is no submission it does seem misleading to have the preview URL still included in the submission response, but it allows the teacher and student to comment back and forth even if they have not submitted the assignment.

In most cases, the preview URL is useful for apps that run in the browser where you may already have logged into Canvas and then the Preview URL would work because it uses the session already in use or if it is an LTI app you have already authorized it to act and log in as you. It doesn't work well in cases where a script is trying to download a submitted assignment and that is where the assignment list is useful because those will allow you to directly download the files without logging in.

shu14
Community Participant

Hi, can you tell me which api to get your results? Thanks you.