Search code examples
google-apps-scriptgoogle-app-maker

Access Admin SDK with Google App Maker


I'm practicing with the early access Google App Maker and want to create a simple app that allows an administrator to change the password of another user in the organisation.

Whenever I try to call the Admin SDK API with something that would have previously worked with App Script, I get an error. It seems to be that App Maker is not allowing access to the SDK API.

I've enabled the Advanced Services > Google Admin Directory API. Is this where I should be able to enable the Admin SDK API (required for changing passwords)

To test, I'm trying to run this simple function:

function listUsers() {
  var response = AdminDirectory.Users.list(optionalArgs);
  var users = response.users;
  if (users && users.length > 0) {
    Logger.log('Users:');
    for (i = 0; i < users.length; i++) {
      var user = users[i];
      Logger.log('%s (%s)', user.primaryEmail, user.name.fullName);
    }
  } else {
    Logger.log('No users found.');
  }
}

The above code returns this error:

AdminDirectory is not defined at NewPage.Button1.onClick:2:18

I'm sure I must be missing something here.

Many Thanks.


Solution

  • AdminDirectory (As well as other advanced services) are available on server side only.

    You should move the method to Server Script and call it with google.script.run on button's click.

    Please use code completion to see available options.