I have several courses that all have the same set of topics with coursework (Assignments) that have the same title in each of those topics. I am trying to delete those assignments from just a few of the topics in each course using Apps Script. I expected to be able to use Classroom.Courses.CourseWork.delete(), but, so far, my code does nothing. No error - just no change in the Assignments. I think my permissions and such are in order, because these are assignments that I created with this same account/permissions.
My issue might be that I am not able to get the coursework ids from the name of the assignment. I'm not sure how to do that, but I think it could be missing from my code.
Here's what I tried:
function deleteAssignments() {
var courseIds = ['100000000000','100000000001','100000000002'];
var topicNames = ['topic3','topic2','topic1'];
for (var i = 0; i < courseIds.length; i++) {
var topics = Classroom.Courses.Topics.list(courseIds[i]).topic;
var topicObj = topics.reduce((o, e) => Object.assign(o, {[e.name]: e.topicId}), {});
for (var j = 0; j < topicNames.length; j++) {
var topicId = topicObj[topicNames[j]];
var exec = Classroom.Courses.CourseWork.delete({
title: "Example Assignment",
topicId: topicId,
workType: "ASSIGNMENT",
}, courseIds[i]);
}
}
}
I checked the Google Classroom courses.courseWork docs, but I think I don't understand well enough how to structure my code as a whole to make use of the info there, because I don't have any background knowledge/training.
I used Problem listing assignments of a student in Google Classroom to come up with my code, but mine is not working and I can't figure out where I'm going wrong.
I also looked at Using Google Apps Script to list assignments through Google Classroom API using course.coursework.list, but when I run the code in the answer, my log says that it's loading, but it never appears to finish.