Reputation: 51
When I use Classroom API to publish an assignment with student copies. I get API call to classroom.courses.courseWork failed with error: Internal error encountered
.
This occurs when I post a Draft successfully, then attempt to use the API to publish the assignment, or when I try to publish a new assignment directly.
Changing the assignment to "view only" solves the publishing problem in both cases but then you do not get student copies and you can not change it back after publishing and student copies are almost always required.
I can manually publish in google classroom after posting a draft with no problems. I assume it is connected to the reason you can not make student copies after posting assignment.
I have probed before publishing and the student folder id is available but has not been created yet.
var assignment = {
title: "Test File",
materials: [
{
driveFile:{
driveFile: {
id: "11klBA-80IQPaJHrpSyJHqVsK7BUWWAtoLFdwG0uJGfo",
title: "Sample Document"
},
shareMode: "STUDENT_COPY"
}
}
],
state: "PUBLISH",
workType: "ASSIGNMENT"
};
var id = Classroom.Courses.CourseWork.create(assignment, 24551294261)
Logger.log(id);
or
Classroom.Courses.CourseWork.patch( {"state": "PUBLISHED"},24551294261,46981225150,{updateMask:'state'});
API call to classroom.courses.courseWork.patch failed with error
is returned with either program code. The code works fine if Student_COPY is changed to view. I believe it is a bug, the API does not have some publishing protocol that manually hitting publish does. So it fails. My guess would be the creation of the google folder to store the documents.
I teach 8 classes publishing each assignment manually takes a long time and if I make errors students may miss an assignment.
Hoping for a workaround or a bug fix. I am using the API to post in part to save time grading and in part to keep all 8 classes the same. I can Updating due dates or instructions without accidentally leaving anyone out. I need the API to post the assignment so it has access to the assignment for changes.
Upvotes: 2
Views: 557
Reputation: 1
If I'm going to schedule it for the future, then I include in the resource:
resource = {
...
state: "DRAFT";
...
};
To publish it immediately, simply set the state to published:
resource = {
...
state: "PUBLISHED";
...
};
and the assignment will immediately go out. Then either way:
var creq = gapi.client.classroom.courses.courseWork.create({courseId:
smeCourseId,resource: resource});
creq.execute(function(courseWork) {
if (courseWork.error) {
window.alert(courseWork.error.message);
}
);
Upvotes: 0
Reputation: 13
Since I don't have enough reputation points, Travis is correct.
UTC Zulu time follows this format: "scheduledTime": "2020-06-08T01:34:55Z",
To print the timestamp, use the following code...make sure to call the below function in your Classroom function.
function schedulePost(){
var now = new Date();
var extra = now.getMinutes()+5;//change the numeric time for the spread
console.log(Utilities.formatDate(now, 'Etc/GMT', 'yyyy-MM-dd\'T\'HH:'+extra+':ss.SSS\'Z\''));
};
Upvotes: 0
Reputation: 51
I found a workaround. You can not publish an assignment with student copy using the API. You can use scheduledTime: for 5 min in the future and the system will publish it for you.
Instead of patching state to publish an existing assignment you can patch schedule it to open it in 5 min. I bit of a pain but publishing 3 assignments for 8 class was taking me half an hour. A 5 min wait is not a bad trade. I have not tested how close to present you can set the time. I use 5 min to allow for any lag.
By the way, patch only works on title, description, state, dueDate, dueTime, maxPoints, scheduledTime, submissionModificationMode, topicId. Materials is not on the list. You can not change the link or the document associated with the assignment.
Upvotes: 2