1
votes

How do I correctly call People.ContactGroups.get in a Google Apps script?

I am migrating a Google Apps script, that manages a contacts list / emailer, to the "people" API. The idea is to extract a list of email addresses of contacts belonging to a particualr group, but I cannot get People.ContactGroups.get to behave at all.

The line

groupdata = People.ContactGroups.get ( { "resourceNames" : group, "maxMembers": 200 } );

consistently fails (group is a string of the form "contactGroups/64e6332b89d0525b").

"Try this API" in the Google People API documentation works OK, but running the code in the Apps debugger yields an incomprehensible error (a page of unprocessed HTML that is truncated so you can't see any content). Badly formatted parameters in other People API functions fail gracefully, with understandable error messages in the debugger, but I simply cannot get ".get" to work at all.

More context:

var group = getGroupResourceName(groupname);
 Logger.log (group);

 var groupdata = People.ContactGroups.get ( { "resourceNames" : group, "maxMembers": 200  } );

  var len = groupdata.memberResourceNames.length;

...etc  (code to extract the list of all email addresses in the contact group)

The function getGroupResourceName(groupname) returns the resourceName of the group with a readable name like "Members", which uses a call to People.ContactGroups.list() with no problem.

(Sample of the error produced:

12:56:14 AM Notice  Execution started
12:56:13 AM Info    contactGroups/4bdcdca10e05c68c
12:56:14 AM Error   
HttpResponseException: Response Code: 404. Message: <!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;
padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* >
 body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}
a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}
#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png)
 no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi)
{#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png)
no-repeat 0% 0%/100% 100%;-moz-border-image:url(//w....
getmailgroup    @ Code.gs:29
run @ Code.gs:17

)

1

1 Answers

1
votes

I thought that in your script, the arguments for People.ContactGroups.get are required to be modified. So, how about the following modification?

From:

var groupdata = People.ContactGroups.get ( { "resourceNames" : group, "maxMembers": 200  } );

To:

var groupdata = People.ContactGroups.get(group, {"maxMembers": 200 });
  • In this case, it supposes that group is the valid resourceName. Please be careful this.

Reference: