gapps-directory

(Unofficial) Google Apps Directory Api client library.

(Unofficial) Google Apps Directory Api client library.

npm install gapps-directory

 
var UsersClient = require('gapps-directory').Users;
 
var usersClient = new UsersClient({
  domain:       'a-gapps-domain.com',
  access_token: 'administrator access token for my application'
});
 
usersClient.getAll(function (errusers) {
  //.. 
});

Otherwise request the first access_token with the offline option and provide a refresh_token, client_id and client_secret as follows:

 
var UsersClient = require('gapps-directory').Users;
 
var usersClient = new UsersClient({
  domain:        'mydomain.com',
  refresh_token: 'x',
  client_id:     'my app client id',
  client_secret: 'my app client secret'
  /* optionally the first token 
  access_token:  'y',
  expires_in:    '3000'
   */
});

Fetch all the users from the directory API for an specific domain.

Options can have any of these maxResults, orderBy, sortOrder, query

Callback has the following arguments:

  • err: if a request return error it will be here
  • users: an array with all users

Return a single page matching the query criteria (options).

Options can have any of these maxResults, orderBy, sortOrder, query and pageToken.

The callback returns a meta object wich has the nextPageToken.

For instance if you want to get only the two first pages:

users.getPage(function (errusersmeta) {
 
  users.getPage({pageToken: meta.nextPageToken}, function (errusersSecondPage) {
 
  });
});

The Google Directory API is bigger than this, it has Groups, Nicknames and so on. You can also create, modify and delete users, groups and nicknames. All this is not supported yet, I will add new things as I need and I will kindly accept pull requests.

You will need a Google Apps account, credentials for some application and the admin of the Google Apps account to authorize your application. Then create a testing-keys.js file in the root of the folder with the following data:

module.exports = {
  "client_id":              "your client id",
  "client_secret":          "your client secret",
  "domain":                 "the-domain-of-the-gapps-account.com",
  "refresh_token":          "an-admin-refresh-token"
};