Downloading Submission File Attachment

Jump to solution
wade_ashby
Community Member

I'm trying to download the actual file the students upload via the API.  I have a list of all the submissions I want to download using the URL

urlAPI_root = url_root+'/api/v1/courses/' + str(assignment.crsID) + '/assignments/' + str(assignment.id) + '/submissions/'+str(submission['user_id'])

I receive the information I need to know about the grade, time submitted and such.  However, it informs me that the submission_type is online_upload but I cannot access the file that was uploaded. Any ideas?

1 Solution
garth
Community Champion

 @wade_ashby ​ you can get a list of all submissions for an assignment using this API call:

Submissions - List Assignment Submissions

This API call will return a json list of submission objects:

Submissions - Submission Object

Here's an example of the syntax:

http://mysite.instructure.com/api/v1/courses/1234/assignments/1234/submissions

Within each submission object that contains an uploaded document, you will see an "attachments" object.

One of the parameters of the "attatchment" is: "url"

This is the URL for the document attached to the submission.

You are able to download the file from this URL.

Here is an example of one of the submission objects that is returned from a test course that I work with, I have highlighted the URL variable in bold text:

  {

    "id": 546,

    "body": null,

    "url": null,

    "grade": "21",

    "score": 21,

    "submitted_at": "2015-07-23T16:12:22Z",

    "assignment_id": 1234,

    "user_id": 1234,

    "submission_type": "online_upload",

    "workflow_state": "graded",

    "grade_matches_current_submission": true,

    "graded_at": "2015-11-12T20:22:50Z",

    "grader_id": 1234,

    "attempt": 1,

    "excused": null,

    "late": false,

    "preview_url": "https://mysite.instructure.com/courses/1234/assignments/1234/submissions/1234?preview=1&version=1",

    "attachments": [

      {

        "id": 5029,

        "folder_id": 1234,

        "display_name": "mysampledoc.docx",

        "filename": "mysampledoc.docx",

        "content-type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",

        "url": "https://mysite.instructure.com/files/1234/download?download_frd=1&verifier=a0r8I2lbKdd3ORdvaRLCVIPtP...",

        "size": 15081,

        "created_at": "2015-07-23T16:12:21Z",

        "updated_at": "2015-07-23T16:12:23Z",

        "unlock_at": null,

        "locked": false,

        "hidden": false,

        "lock_at": null,

        "hidden_for_user": false,

        "thumbnail_url": null,

        "modified_at": "2015-07-23T16:12:21Z",

        "locked_for_user": false,

        "preview_url": "/api/v1/canvadoc_session?blob=%7B%22user_id%22:61240000000000033,%22attachment_id%22:5029,%22type%22:%22canvadoc%22%7D&hmac=0b1bcf1a12345fdaec654321d1e48c0bfc6b1167"

      }

    ]

  }

I hope this helps.

View solution in original post