2

Using Google Classroom API, I am simply trying to create a coursework (assignment) where I can assign the Drive folder for that coursework then I can upload attachments into that specific folder.

I've tried on the browser with their API Explorer and also does not work.

Here's my code;

    const classroom = google.classroom({version: 'v1', auth});
    classroom.courses.courseWork.create({
        "courseId": assignmentCreationRequest.courseId,
          "resource": {
            "title": assignmentCreationRequest.title,
            "description": assignmentCreationRequest.description,
            "workType": "ASSIGNMENT",
            "state": "PUBLISHED",
            "topicId": assignmentCreationRequest.topicId,
            "assignment":
            {
                "studentWorkFolder": {
                  "id": "1wTM6YYAk1rp4TtsEQwjZnb3qMbR9iPbe"
                }
            }
          }
    })

The folder has been created inside the Classroom courses folder as parent.

The only way I found working to create such folder is; when creating a coursework, add materials where the share mode is set to 'STUDENT_COPY', then the API will create a folder themselves. It's a workaround where I can delete all of the contents once the folder is created, but surely there's a classier way?

Any help would be massively appreciated!

smkso
  • 95
  • 1
  • 6

2 Answers2

1

Answer:

You cannot assign a specific, previously existing Drive folder to a CourseWork.

This folder is automatically created by Google when creating the CourseWork, if the workType is ASSIGNMENT.

Also, the studentWorkFolder will only be created if there's content to place there, be it a studentSubmission or Material attached to the course work.

Reference:

If you check the CourseWork fields, you will see that, assignment (containing studentWorkFolder) is read-only:

assignment: Assignment details. This is populated only when workType is ASSIGNMENT.

Read-only.

Therefore, this field will be ignored.

Iamblichus
  • 18,540
  • 2
  • 11
  • 27
  • I've tried without assigning a specific, previously existing Drive folder but that doesn't work. Once the assignment is created, no folder is created automatically for that assignment, unless there are submissions or attachments from students. I can modifyAttachments for newly created assignment since no such folder created. Is that a way to trigger the folder creation once the assignment is created? – smkso Nov 23 '20 at 18:56
  • @smkso The `studentWorkFolder` will only be created if there's content to place there, be it a `studentSubmission` or `Material` attached to the course work. If you think this is not appropriate for your situation, I'd suggest you to file a Feature Request in Issue Tracker. – Iamblichus Nov 24 '20 at 13:14
  • @lamblichus I get it now. I've found a way to work for my situation. Thanks – smkso Nov 24 '20 at 20:12
1

As @lamblichus replied, it is not possible to assign specific folder when creating a courseWork.

The studentWorkFolder will only be created when;

  1. You provide material with shareMode set to STUDENT_COPY.
  2. When student submit attachments to their submission.

For my case where for each submission, I'd like to modifyAttachments with custom files, I have created a folder with the name of the course then placed all of the attachments in the folder with correct permissions, then using modifyAttachments I add the file ID to the submission ID. This still won't create a studentWorkFolder but I'm able to modifyAttachments for each student.

If I were to add materials where the shareMode is STUDENT_COPY, which this will create studentWorkFolder containing the files, then I were to delete all of the contents of the folder; this means I will have a studentWorkFolder however on the courseWork, the materials attached will still be available/shown. patch wouldn't allow to update materials.

I hope this helps those also in similar situation.

smkso
  • 95
  • 1
  • 6