Search code examples
javascriptgoogle-apps-scriptgoogle-classroom

Classroom API IndividualStudentsOptions in Google Apps Script


Is it possible to use IndividualStudentsOptions object from Google Apps Script? I'm trying to create the object but returns this error

GoogleJsonResponseException: No se ha podido llamar a la API classroom.courses.courseWork.create; error: Invalid JSON payload received. Unknown name "individualStudentsOptions" at 'course_work': Proto field is not repeating, cannot start list.

It seems that is not possible from GAS.

function enviarclassdos(datos,alumnos){

// datos: object with needed variables for classroom publishing
// alumnos: individual students  (array [students])

var stdid = []; //Array of IDs of individual students

//Getting the IDs of the individual students

var hojacuentas = SpreadsheetApp.openById("1oHlpSyRB913LWpj-UNTKattO").getSheetByName("CUENTAS");
var datacuentas = hojacuentas.getDataRange().getValues();
for(var al =0; al<alumnos.length; al++){

var alum = alumnos[al][0];
for (var dt=0; dt<datacuentas.length; dt++){
var alumdt = datacuentas[dt][0];

if (alumdt == alum){
var cuenta = datacuentas[dt][3];
stdid.push(cuenta);}}}
 
  var curso = datos.curso;
  var tipo = datos.tipo;
  
  if (curso == "Primero A"){var id = "14085771****";} 
  if (curso == "Primero B"){var id = "14085996****";}
  if (curso == "Segundo A"){var id = "14085996****";}
  if (curso == "Segundo B"){var id = "14085996****";}
  if (curso == "Cuarto AB"){var id = "14085996****";}
  
  var titulo = datos.concepto;
  var descripcion = datos.descripcion;
  var fecha = datos.fecha;
  
  var tema = datos.tipo
  
  
 
var ClassSource =
{
  title: titulo,
  description: descripcion,
  state: "PUBLISHED",
  workType: "ASSIGNMENT",
  topicId: tema,
  maxPoints: 100,
  assigneeMode: "INDIVIDUAL_STUDENTS"
  
}

//This is the object that produces the error message

ClassSource.individualStudentsOptions = {studentIds:stdid};

var clss = Classroom.Courses.CourseWork;
var wrk = clss.create(ClassSource, id);



 }

Solution

  • Instead of

    ClassSource.individualStudentsOptions = [{studentIds:stdid}];
    

    use

    ClassSource.individualStudentsOptions = {studentIds:[stdid]};
    

    Reference