I've created a new google app through their app maker interface. I've added "Google Admin Directory API" as a service and "Directory" as a data source. I created a page that will hold 2 tables, one that list all users within my domain (this is already working) and another table that lists all of the groups within my domain (not working). How can I achieve this? Can this be done through their widgets or do I have to create a script and programmatically call the admin API to then bind the data to the table?
0
votes
You have to do it through scripts.
- Morfinismo
@Morfinismo I've added a script to the app and pasted the "ListAllGroups" sample code I found here github.com/gsuitedevs/apps-script-samples/blob/master/advanced/…, but I get an error "Uncaught ReferenceError: AdminDirectory is not defined at page = AdminDirectory.Groups.list({ (NewScript:8)". Do I have to enable google API scripts in order for my app to be able to talk to the admin API?
- jorgeAChacon
You are probably using that code in the client script and not in the server script. You have to use it in the server scripting.
- Morfinismo
@Morfinismo please see my comment below.
- jorgeAChacon
1 Answers
1
votes
Since you already enabled the Admin Directory API when using the directory model, all you have to do now is to call the sample code from the server script. In a server script, add the sample code:
function listAllGroups() {
var pageToken;
var page;
do {
page = AdminDirectory.Groups.list({
domain: 'example.com',
maxResults: 100,
pageToken: pageToken
});
var groups = page.groups;
if (groups) {
for (var i = 0; i < groups.length; i++) {
var group = groups[i];
Logger.log('%s (%s)', group.name, group.email);
}
} else {
Logger.log('No groups found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
}
Then you can simply call the server script by using the following in the client scripting:
google.script.run.withSuccessHandler(function(response){
console.log(response);
}).withFailureHandler(function(err){
console.log(err);
}).listAllGroups();
You can check the reference here. I hope this helps!