0

I'm new to google apps scripts and I'm running into an error I cant figure out how to correct. The script below runs correctly scrips apps editor, but when I call the function from my spreadsheet I get an error that line 6 (the call to AdminDirectory.Groups.list) is missing required auth credentials.

function listAllGroups() {
  let pageToken;    //this will store the json responce
  let page;
  var retArray = [];
  do {
    page = AdminDirectory.Groups.list({
      domain: 'mydomain.com',
      maxResults: 400,
      pageToken: pageToken
    });
    const groups = page.groups;
    if (!groups) {
      Logger.log('No groups found.');
      return;
    }
    // Print group name and email.
    for (const group of groups) {
      //Logger.log('%s (%s)', group.name, group.email);
      retArray.push(group.name);  //add the current group name to the array
    }
    pageToken = page.nextPageToken;
  } while (pageToken);
  Logger.log(retArray);
  return retArray;
}

When I run it in the editor console the second to the last statement Logger.log() does show me the list of groups I want, but like I said I get the error when I call listAllGrous() from my spreadsheet.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Hal Clark
  • 3
  • 1
  • Take a look and UrlFetchApp headers and ScriptApp.getOauthToken() – Cooper May 05 '22 at 20:34
  • Welcome to [so]. Try opening your spreadsheet and run the script in incognito mode, signing in only using your domain admin account. – Rubén May 06 '22 at 00:55

0 Answers0