I have a Google Apps Script feature used to set up accounts for new employees in our Google Apps domain.
The first thing he does is make calls to the Google Admin settings API and get currentNumberOfUsers and maximumNumberOfUsers , so he can see if there are places available (otherwise this is the next step in which the user is created using the Admin API SDK API will fail).
It worked fine until recently, when our domain had to migrate from Postini to Google Vault to archive emails.
Before migrating when creating a Google Apps user using the Admin Directory Directory API , this will increase currentNumberOfUsers by 1, and the new user of the user account will automatically gain access to all Google Apps services.
Now, after the transfer, when creating the Google Apps user, the โlicenseโ is not automatically assigned, so I changed my Script to use the Enterprise License Manager API , and now it assigns the "Google-Apps-For-Business" license. It works great.
However, currentNumberOfUsers is now different from the number of licenses assigned, and "Google-Apps-For-Business" is just one of several different types of licenses available .
I can get the current number of licenses assigned to "Google-Apps-For-Business" doing this:
var currentXml = AdminLicenseManager.LicenseAssignments.listForProductAndSku('Google-Apps', 'Google-Apps-For-Business', 'domain.com', {maxResults: 1000}); var current = currentXml.items.toString().match(/\/sku\/Google-Apps-For-Business\/user\//g).length;
But the number that produces is different from currentNumberOfUsers .
All I really need to do is get the maximum number of licenses owned by "Google-Apps-For-Business" so that the new Script employee setup can determine if there are any available.
I checked the API reference documentation for the following APIs, but ...
Enterprise License Manager API โ Does not have a method to obtain the maximum or available number of licenses.
Google Admin Settings API โ Not for licenses, only "users".
API Admin SDK Directory user resource โ Not related to licenses.
Google Apps Reseller API This API seems to have what I need, but it is only for reseller accounts .
I know that I can program my new Script employee setup to just see try / catch if he can create a user and assign a license, and finish the Script execution gracefully if he can't, but that doesn't seem to be effective.
Also, part of the old Script was that if there were fewer seats for X, he would email me heads-up to order more. I know that I can program a cycle that tries to repeatedly create dummy users and assign them licenses and count the number of times that it can do before it fails, and then delete all the dummy users, but, again, this is ineffective in general .
Any ideas?