0

I am writing a Google App Script that pulls Chromebook device information from gSuite. I need to export it as a CSV to ingest it into a database. I ran into an issue, however. The API 'AdminDirectory.Chromeosdevices.list' is limited to 100 maxResults. I have over 30,000 results.

Here is my test code.

function updateDeviceList() {
  var page, pageToken, row, dateTime;

  dateTime = getDateTime();

  deleteAllRows();

  do { 
    page = AdminDirectory.Chromeosdevices.list("my_customer", 
      { 
        domain: 'redclayschools.com',
        maxResults: 115,
        orderBy: 'annotatedUser',
        pageToken: pageToken,
        projection: 'full',
        query: 'id:*'
      });

    for (i in page.chromeosdevices) {
      row = getLastRow();
      writeToCell(row, 1, page.chromeosdevices[i].orgUnitPath);
      writeToCell(row, 2, page.chromeosdevices[i].annotatedUser);
      writeToCell(row, 3, page.chromeosdevices[i].annotatedLocation);
      writeToCell(row, 4, page.chromeosdevices[i].annotatedAssetId);
      writeToCell(row, 5, page.chromeosdevices[i].serialNumber);
      writeToCell(row, 6, page.chromeosdevices[i].lastEnrollmentTime);
      writeToCell(row, 7, page.chromeosdevices[i].deviceId);
      writeToCell(row, 8, page.chromeosdevices[i].bootMode);
      writeToCell(row, 9, page.chromeosdevices[i].recentUsers);
      writeToCell(row, 10, page.chromeosdevices[i].macAddress);
      writeToCell(row, 11, page.chromeosdevices[i].lastSync);
      writeToCell(row, 12, page.chromeosdevices[i].osVersion);
      writeToCell(row, 13, page.chromeosdevices[i].platformVersion);
      writeToCell(row, 14, page.chromeosdevices[i].activeTimeRanges);
      writeToCell(row, 15, page.chromeosdevices[i].model);
      writeToCell(row, 16, page.chromeosdevices[i].etag);
      writeToCell(row, 17, page.chromeosdevices[i].firmwareVersion);
      writeToCell(row, 18, page.chromeosdevices[i].status);
      writeToCell(row, 19, page.chromeosdevices[i].ethernetMacAddress);
      writeToCell(row, 20, page.chromeosdevices[i].notes);
      writeToCell(row, 21, dateTime);
    }
  } while (pageToken){

  }
}

And my helper functions (this shouldn't matter):

function writeToCell(row, column, text) {
    sheet.getRange(row, column).setValue(text);
}

Is there a better function to use (I can't seem to find anything), or a way around the 100 maxResult limit? I know the approach with writing directly to the row isn't efficient, this is only test code.

Thanks!

mackhax0r
  • 435
  • 2
  • 7
  • 16

1 Answers1

1

Yes, based from this documentation, the API returns a default and a maximum of 100 entries per page for Chrome and mobile devices. Suggested action is to retry using exponential back-off. You need to slow down the rate at which you are sending the requests.

abielita
  • 13,147
  • 2
  • 17
  • 59
  • Thank you. I seen that before some reason didn't look at it fully. I implemented that, and the next issue I ran into was moving to the next "page" - that has been implemented as well.. it was fairly simple. Thank you again. – mackhax0r May 08 '17 at 19:32