Posting files to Google Classroom using Apps Script

61 views Asked by At

I have been using the code below to post individual students' documents to a Google Classroom.

function postDoc(){ 
  const myCourseID = 24551294265;
  const myData = mySheet.getDataRange().getValues();  

  myData.forEach(function(myRow, index){

  if(index === 0){return;}   

  const myGmail = myRow[0]; 
  const myDocId = myRow[14]; //assigns the pdf file ID     
    
  var myMaterial = {
      assigneeMode: "INDIVIDUAL_STUDENTS",
      individualStudentsOptions: { studentIds: [myGmail] },
      title: "Report Document",
      materials: { driveFile: {driveFile:{id: myDocId}}}       
  };
  
  try{      
     const myNewReport = Classroom.Courses.CourseWorkMaterials.create(myMaterial, myCourseID);       
  } 
  catch(err){    
     console.log('Failed with error %s', err.message);      
  } 
 }); 
}

But, since last week, I am getting the following error message:

API call to classroom.courses.courseWorkMaterials.create failed with error: Precondition check failed.

0

There are 0 answers