2

This is a two part question, regarding the Google Script API.

First, I can read the SDK/API reference, and execute examples successfully, via the "try now" feature. But, what I am missing a step in understanding when trying to build webApps (with limited javascript knowledge - admittedly). Namely, the SDK shows the syntax for many things but not in the way I would expect to use it within Javascript.

A concrete example of my problem: I am trying to create a simple function to return verification Codes (8-digit codes) from the Admin API. Here is an example function.

function getCodes(){
  var userEmail = 'testuser@exampl.com';
  var user = AdminDirectory.Users.list({userKey: userEmail}).verificationCodes;
  Logger.log('User data:\n %s', JSON.stringify(user, null, 2));

}

naturally, the syntax for the AdminDirectory call is wrong, I get errors. I have tried many different variation, but without a proper understanding of the reference, I feel like I am just guessing (and I have guessed a lot).

Can someone throw me a bone? Thanks

TheMaster
  • 45,448
  • 6
  • 62
  • 85

1 Answers1

2
  • Have a look at the Users resource
  • You will see that verificationCodes is not part of this resource
  • However, there is a way to retrieve verification codes: with VerificationCodes: list
  • To usew the latter, you need to provide the userEmail as parameter
  • So modify your request to:
 AdminDirectory.VerificationCodes.list(userEmail).items.forEach(function(item){Logger.log('Code: ' + item.verificationCode)});
ziganotschka
  • 25,866
  • 2
  • 16
  • 33
  • 1
    Thank you! This worked wonderfully. I will try to bridge your help with making better use of the API In the future. Already I have learned how to read it a bit better. – Avogadro Alvares Nov 24 '20 at 12:22