2

Inexperienced at this - please forgive any wrong choices of words...

I'm trying to use Google Apps Script to get a list of assignments set within different classrooms. I believe I have all the appropriate APIs, credentials and scopes required. I followed the tutorial for setting up a simple class list, which worked, then edited to try to list the assignments within each class as below:

/**  
 * Lists 100 course names and ids.
 */
function listCourses() 
{
  var optionalArgs = {
    pageSize: 100
  };
  var listArgs = {
    pageSize: 10
  };
  var response = Classroom.Courses.list(optionalArgs);
  var courses = response.courses;
  if (courses && courses.length > 0) 
  {
    for (i = 0; i < courses.length; i++) 
    {
      var course = courses[i];

      Logger.log('%s (%s)', course.name, course.id);

      var info = Classroom.Courses.CourseWork.list(listArgs);
      var works = info.works;
      if (works && work.length > 0) 
      {
        for (i = 0; i < works.length; i++) 
        {
          var work = works[i];

          Logger.log('%s (%s)', work.title, work.creationTime);
        }     
      }
    }
  }
}

Error was: Requested entity was not found. (line 22, file "Code")
*Line 22: var info = Classroom.Courses.CourseWork.list(listArgs);

Any ideas appreciated, thanks

Mr Scott
  • 21
  • 3
  • It's time to debug! What is at line 22? Work backwards from there. The error message is well discussed here and on the greater unwashed web. Use this information to work from the known to the unknown. –  Dec 12 '18 at 20:37

1 Answers1

2

This line: var info = Classroom.Courses.CourseWork.list(listArgs);

Should be: Classroom.Courses.CourseWork.list(courseId, optionalArgs)

Or this: Classroom.Courses.CourseWork.list(courseId)

The point is that courseId is required.

You can try it on the API Explorer Here.

So the code should look something like this:

function listCourses() {
  var optionalArgs = {pageSize: 100};
  var listArgs = { pageSize: 10 };
  var response = Classroom.Courses.list(optionalArgs);
  var courses = response.courses;
  if (courses && courses.length > 0) {
    for (i = 0; i < courses.length; i++) {
      var course = courses[i];
      Logger.log('%s (%s)', course.name, course.id);
      var info = Classroom.Courses.CourseWork.list(course.id, listArgs)
      var works = info.works;
      if (works && work.length > 0) {
        for (i = 0; i < works.length; i++) {
          var work = works[i];
          Logger.log('%s (%s)', work.title, work.creationTime);
        }     
      }
    }
  }
}

But check it out carefully because this is the first time I've ever enabled the Classroom API.

Cooper
  • 59,616
  • 6
  • 23
  • 54