I'm using Google Apps Script to change the names of a few Topics in several Google Classrooms. I'm using Classroom.Courses.Topics.patch()
to change only the 'name' value of the Topics, but my script does not change anything when I look at the Classrooms.
Here is an example: I have two Classrooms (course IDs '100000000000' and '100000000001'). In each Classroom I have three Topics (topic names 'topic1', 'topic2', and 'topic3'). I want to change the name of the first two topics to 'newtopic1' and 'newtopic2' respectively, in both classrooms.
I suspect there could be something off with the way I'm doing the update mask, but I've tried re-ordering things, and I still can't get it to go... Could also be my nested for loops?
function updateTopicNames() {
var courseIds = ['100000000000','100000000001'];
var topicNamesOld = ['topic1','topic2'];
var topicNamesNew = ['newtopic1', 'newtopic2'];
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 < topicObj.length; j++) {
for (var k = 0; k < topicNamesNew.length; k++) {
var topicId = topicObj[topicNamesOld[j]];
var newName = {'name':topicNamesNew[k]};
var extra = {'updateMask':'name'};
var exec = Classroom.Courses.Topics.patch(newName, topicId, courseIds[i], extra);
}
}
}
}
I checked out the courses.topics.patch API, but there is no example of the update mask implementation for me to extrapolate from.
I tried to bootstrap from code for other .patch()
things: StudentSubmissions.Patch UpdateMask Error and How to change course owner using Classroom.Courses.patch() but something is not working when I try to convert these for Topics.patch()
.