file attachment to dropbox feedback by API
I am following up on a post that I had last week after consulting with my admin. I am working on a Python API to automate several processes with my LMS (grades, dropbox). I have encountered issues uploading files to the dropbox feedback as an attachment with the resumable process. I pretty sure the established scopes are correct. The code has been setup to give detailed logging. For a reference, the calls I am looking at are: see POST /d2l/api/le/(version)/(orgUnitId)/dropbox/folders/(folderId)/feedback/(entityType)/(entityId)/attach and POST /d2l/api/le/(version)/(orgUnitId)/dropbox/folders/(folderId)/feedback/(entityType)/(entityId)/upload (this is the first step.) As noted, a resumable process is required. ( ).
The code gets the 308 incomplete (returns a filekey) and then subsequently returns 404 errors when I try to upload in chunks. As my admin noted this either could be an incorrect path (I'm taking the /d2l/upload/*key* and appending it to the university's url "https://unversity.edu"-i.e., the same one I use for other calls such as grades, dropbox downloads, etc) or the lifetime of the folder. Has anyone encountered this previously? Is there an alternative path that I should be using? The calls and headers (some information scrubbed) I have used for the two steps are below this email.
Thanks in advance for any help you can provide! When this is done I'd like to make the Python code available to the community. I'm also happy to share the GUI I've started to put together related to dropbox/grades (does an MPI downlaod of dropbox submissions). Some things are customized to a particular course I am teaching.
Sincerely,
Sean
PS. Here is the jist of what my code is calling per the log files and the returned codes. Note that my LMS path is scrubbed as are the tokens.
- My first post to (generalized here) calls https://University.edu/d2l/api/le/1.75/XXXCourseIDXXX/dropbox/folders/XXXXFolderIDxxx/feedback/user/StudentID/upload with a header:
{
"Authorization": "Bearer TOKEN STRING omitted",
"X-Upload-Content-Type": "text/plain",
"X-Upload-Content-Length": "53",
"X-Upload-File-Name": "test.txt",
"Content-Length": "0",
"Origin":
}
- It returns:
- STATUS: 308 Resume Incomplete
- Location: /d2l/upload/XXXXXX
- GOOD- as this is expected
- The subsequent step called is where I get a 404 and have questions. The call is to:
- https://University.edu/d2l/upload/XXXXXXX (where XXXXX was the file key returned above.
- Header:
{
"Authorization": "Bearer TOKEN",
"Content-Type": "application/offset+octet-stream",
”Content-Range": "bytes 0-52/53",
"Content-Length": "53",
"Origin": "https://University.edu"
Answers
-
Hi @Sean.R.636,
Thanks for reaching us through the community!!
Did you try reaching out to us through a support case? We might need to understand the Dropbox details, user details, set up details and feedback uploaded.
Based on what you’re describing, I think it would be a good idea to have a support agent take a closer look at things.
Your first step is to connect with your school or organisation’s Help Desk to create a support request.
If you’re not sure how to do this, email us at questions@community.d2l.com with the name of your school or organisation, and we can provide the contact details.
If you are the ASC/ Admin for your organisation, please refer to our documentation for how to log a Support case or request, and a member of our Support team will be happy to assist you.
Thanks,
Sangeetha
-
Hi Sangeetha,
I had not pursued that exact course, but I did successfully get a file to upload. I was planning to clean up some of what I did and will share it with the community. I was going to upload the script the other night but found I couldn't upload a Python file directly. I have to scrub some info from the script (folder_id, course_id were hard coded for debugging process). I just completed a script for bulk upload from a folder (files were structured to follow the pattern of bulk dropbox file downloads). I'm hoping to make the complete set of scripts available to the community. They are primarily focused on the dropbox and grade APIs.Sincerely,
Sean -
Hi Sean,
That’s great to hear you got the upload working! The bulk upload script and GUI sound really useful—thanks for planning to share them with the community. If you run into any issues posting Python files, you could zip them or share via a GitHub link for easier access.
Looking forward to seeing your scripts and learning from your approach!
Raquel -
Raquel,
Sounds good. I like the zip idea in particular. The code is currently "Frankensteined" and as noted very particular to my primary class at the moment. Many (but not all) of the API calls are in a python script external to the GUI. I am using openssl in conjunction with Python to get the necessary port for OAuth2.0/token exchange. I may have to revisit with my admin our choice of the port. I'm using Microsoft's MPI for parallel downloading (mpi4py in Python). The current program has the hidden parameters (i.e., the CLIENT_ID, CLIENT_SECRET, REDIRECT_URI). I also hard programmed the D2L course ID and a few other paths (an RIT Google Drive) in.
I've invested most of my time into a button that (i) selects a dropbox, (ii) identifies all submissions, (iii) downloads them to my PC and add names/ids analogous to the Zip file bulk download that the standard UI has (some have the d2lID and folder ID, others just LastName, FirstName), (iii) It looks at a Google Drive path I use to move files for grading and determines if they have already been looked at or not, (iv) takes any files that were graded, and moves them back to my local drive, and (v) bulk uploads them as attachments to the appropriate dropbox/student (similar to if you upload the files from the dropbox bulk upload in the UI). In (v), I had to first delete any existing feedback files via the API, and then upload the new file. I tested it out on new submissions from students today (I had a cohort who was willing to work with me). The file attachment is done in parallel also. The total sequence of (i)-(v) runs much faster than any of the individual steps.
The script has a number of other buttons I used for staging on the dropbox tab. I will have to carefully clean things up. I've also got some functionality with gradebook implemented with a pseudo-spreadsheet interface. If I can change cell properties to allow bullets/etc, that would help in posting more meaningful feedback.I'll share some more over the next few weeks. My son is coming back for Thanksgiving (college break) tomorrow so I'll likely have to put the script down short of using it for grading/file manipulation. I'd also be happy to Zoom at some point after the holiday.
Sincerely,
Sean
