0

When I run this code I get the value 500 as courses.length. I deleted 1 classroom, but I obtained 500 again. I suppose that number of classroom is higher, but I see always 500 classroom. What's my mistake?

function listadeicorsi()
{

       const ss=SpreadsheetApp.getActiveSpreadsheet();
       const sh1=ss.getSheetByName("Classroom");
       var page = Classroom.Courses.list();  
       var courses = page.courses;
       if (courses && courses.length > 0)
       {
            sh1.getRange(1,8,1).setValue(courses.length);
       }
       else
       {
           sh1.getRange(x,1,1).setValue("CLASSROOM NON TROVATE");
       }
 }
Rubén
  • 34,714
  • 9
  • 70
  • 166

1 Answers1

0

You missed that Classroom API results are paged, in other words they are capped.

From https://developers.google.com/classroom/reference/rest/v1/courses/list:

pageSize integer
Maximum number of items to return. Zero or unspecified indicates that the server may assign a maximum.
The server may return fewer than the specified number of results.

If you want to make a list of all the courses you have to use the pageToken and use some sort of iteration as the results might be fewer even if you set a large pageToken.

Related

Rubén
  • 34,714
  • 9
  • 70
  • 166