Differentiate between enterprise vs individual users

62 views
Skip to first unread message

Andrew A.

unread,
Aug 23, 2019, 11:48:23 AM8/23/19
to google-apps-sc...@googlegroups.com
I searched and couldn't find any topic like this, much to my surprise. I was convinced someone would have asked about this by now.
Anyway, does anyone here have a working implementation that helps developer to distinguish between individual and enterprise users?
If so, do you mind sharing it?

Jonathan Butler

unread,
Aug 23, 2019, 11:57:48 AM8/23/19
to google-apps-sc...@googlegroups.com
One slightly cheap hacked together way of doing it to check the Mail App Quota. If the quota is higher than 100 than it must be an enterprise account.

On Fri, Aug 23, 2019 at 11:48 AM Andrew A. <chis...@gmail.com> wrote:
I searched and couldn't find any topic like this, to my surprise. I was convinced someone would have asked about this by now.
Any way, does anyone on this forum have a working implementation that helps developer to distinguish between individual vs enterprise users?
If so, do you mind sharing it?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/a362944c-de24-4e06-abca-79636287738b%40googlegroups.com.

Andrew A.

unread,
Aug 23, 2019, 12:15:42 PM8/23/19
to Google Apps Script Community
Interesting idea but it might alienate developers like me who are not working on mail apps


On Friday, 23 August 2019 18:57:48 UTC+3, Jonathan Butler wrote:
One slightly cheap hacked together way of doing it to check the Mail App Quota. If the quota is higher than 100 than it must be an enterprise account.

On Fri, Aug 23, 2019 at 11:48 AM Andrew A. <chis...@gmail.com> wrote:
I searched and couldn't find any topic like this, to my surprise. I was convinced someone would have asked about this by now.
Any way, does anyone on this forum have a working implementation that helps developer to distinguish between individual vs enterprise users?
If so, do you mind sharing it?

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Andrew A.

unread,
Aug 23, 2019, 12:20:45 PM8/23/19
to google-apps-sc...@googlegroups.com
This might be a start:

function myFunction() {
 
var str = "us...@example.com";
 
var res = str.split("@")[1];
}

So I intend to use it like this:

function myFunction(){
 
var a = Sessions.getEffectiveUser().getEmail();
 
var res = a.split("@")[1];
 
if( res == "gmail.com"){
 
// Do something;
 
} else {
 
// Do another thing;
 
}
}

Poke holes in my logic

Alan Wells

unread,
Aug 24, 2019, 10:15:35 AM8/24/19
to google-apps-sc...@googlegroups.com
To get a domain name, make a post request to the user info url, which is the REST API url.

  var domainName,param,response,url,user,userinfo;


  url
= "https://www.googleapis.com/oauth2/v2/userinfo";
 
  user
= Session.getEffectiveUser().getEmail();

 
//The above "user" variable is not used but the above line is to be certain that the permission gets approved -
 
//If the scope was not set in the manifest file and there was no other line of code to prompt the user to authorize
 
//that permission- then the code would fail - that why the above line of code is there to cause the authorization process
 
//to ask the user to authorize this scope

  param
= {
   
"method" : "get",
   
"headers" : {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
   
"muteHttpExceptions":true,
 
};

  response
= UrlFetchApp.fetch(url, param).getContentText();
  userinfo
= JSON.parse(response);

 
//Logger.log(JSON.stringify(userinfo,null,2));

 
if (userinfo) {
    domainName
= userinfo.hd ? userinfo.hd : false;

  }



It returns information in the form of:


{
 
"id": "10",
 
"email": "na...@domainname.com",
 
"verified_email": true,
 
"name": "First Last",
 
"given_name": "First",
 
"family_name": "Last",
 
"picture": "https://lh3.googleusercontent.com/a-/",
 
"hd": "domainname.com"
}

Andrew A.

unread,
Aug 24, 2019, 12:02:37 PM8/24/19
to Google Apps Script Community
Thanks for posting this.
Does this mean that the code I posted is inadequate to determine if a user has an individual account or not?

Andrew A.

unread,
Aug 24, 2019, 12:27:22 PM8/24/19
to Google Apps Script Community
.I guess my curiosity is this: What advantage does this hold over checking if the email ends with "@gmail.com"?

Alan Wells

unread,
Aug 24, 2019, 1:26:14 PM8/24/19
to Google Apps Script Community
I don't know if there are situations where one fails and the other succeeds.  I'd think that using the API might be more reliable to get the domain name.

Andrew A.

unread,
Aug 24, 2019, 2:02:51 PM8/24/19
to google-apps-sc...@googlegroups.com
Ok... I'll  depend on your experience then.
I hope the rule that "gmail.com" is for individuals remains the same...

EDIT:
It seems that your code even resolved an issue I was getting with permissions. My code was throwing exceptions before this change.

Andrew A.

unread,
Aug 24, 2019, 3:10:10 PM8/24/19
to google-apps-sc...@googlegroups.com
The response I am getting looks like this:

{
  id
=1...2,
  verified_email
=true,
  email
=o...@gmail.com,
  picture
=https://lh3.googleusercontent.com/a-/...
}

... looks like the hd property is missing

Alan Wells

unread,
Aug 24, 2019, 4:18:14 PM8/24/19
to google-apps-sc...@googlegroups.com
Don't depend on me for anything.  Sooner or later, you'll be very disappointed. ;)

On Sat, Aug 24, 2019 at 2:02 PM Andrew A. <chis...@gmail.com> wrote:
Ok... I'll  depend on your experience then.
I hope the rule that "gmail.com" is for individuals remains the same...

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/354efe8c-05be-429d-b3ce-453e52985306%40googlegroups.com.

Andrew A.

unread,
Aug 24, 2019, 5:04:46 PM8/24/19
to Google Apps Script Community
The old trust but verify approach...
That is why I tested to see what exactly this method was returning and sure enough the hproperty is missing.
But it looks OK so I will keep it (fingers crossed)
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

Dimu Designs

unread,
Aug 24, 2019, 6:08:12 PM8/24/19
to Google Apps Script Community
I think I read back on the old G+ forums that the "hd" property is only present for GSuite domains. So it should serve as a means to differentiate between consumer and GSuite domain account types.


On Friday, August 23, 2019 at 11:48:23 AM UTC-4, Andrew A. wrote:

Amit Agarwal

unread,
Aug 25, 2019, 2:22:45 AM8/25/19
to google-apps-sc...@googlegroups.com
This might not work in some cases because the MailApp quota is capped at 100 for GSuite accounts that are new or in the trial period.

Amit Agarwal  
blog: labnol.org    shop: digitalinspiration.com



Stéphane Giron

unread,
Aug 25, 2019, 6:26:06 AM8/25/19
to Google Apps Script Community
Hi

The aj solution is the best because you can create a consumer account with any emails so you can have users with yahoo.com email that are not G Suite users. Worst you can have a user with company that create account without email and is considered as consumer.

Best is to check hd property to be sure.

Stéphane
Reply all
Reply to author
Forward
0 new messages