I'm programmatically submitting a Google Classroom assignment, and I'm seeing different behavior when attach a Material using the STUDENT_COPY shareMode than when I use the VIEW shareMode.
The following code seems to be working fine:
var resource = {
title: name,
description: explanation,
workType: 'ASSIGNMENT',
state: 'PUBLISHED'
};
resource.materials = [];
resource.materials.push({
driveFile: {
driveFile: {
id: 'fileId'
},
shareMode: 'VIEW'
}
});
var params = {auth: creds, courseId: courseId, resource: resource};
classroom.courses.courseWork.create(params, function (err, courseWorkResponse) {
/* handle response */
}
With that code, the assignment gets created and I can see it in Google Classroom. However, if I set the shareMode to STUDENT_COPY instead of VIEW, I get the following error:
{ Error: Requested entity was not found.
at Request._callback (/Users/.../node_modules/googleapis/node_modules/google-auth-library/lib/transporters.js:85:15)
at Request.self.callback (/Users/.../node_modules/googleapis/node_modules/request/request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/Users.../node_modules/googleapis/node_modules/request/request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (/Users/.../node_modules/googleapis/node_modules/request/request.js:1091:12)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20)
code: 404,
errors:
[ { message: 'Requested entity was not found.',
domain: 'global',
reason: 'notFound' } ] }
The assignment is not being created in Google Classrom. However, I am seeing a [Template] copy of the Google Doc I specified in the driveFile.id being placed into my Google Drive.
I've tried this with several different documents, some of which were basically "Hello World"-level google docs, so I doubt the issue is related to the document.
Other than that, I'm not sure what could be going on. I assume there must be some sort of permissions issue somewhere, but does anybody else have a clue what might be going on?
EDIT: Further information
It seems to be an issue with "publishing" the assignment. If I set the resource.state
to DRAFT
, I'm able to successfully execute the coursework.create
API call. I get back an instance of a CourseWork object as expected.
The problem is I need to ultimately PUBLISH the assignment. And when I try to execute the classroom.courses.courseWork.patch()
api call to simply change the state from DRAFT to PUBLISHED, I end up getting the same Requested entity was not found
error.
However I am able to go into Google Classroom itself, view my drafts, and click on the ASSIGN button in the application. If I do that, everything finally works! That UI flow is no good for me, though. But it does indicate that there's nothing inherently wrong, as far as I can tell, with the assignment. I just seem to be missing some (undocumented?) step that's necessary in my case.