I appreciate any pointers you might have...
I am trying to get the Google Contacts email address for a given name using script. In a really dumb way, I have been successful using the following:
var address = ContactsApp.getContactsByName("name goes here")[0].getEmailAddresses()[0];
But I have read that ContactsApp is deprecated and that I should use the "People" api instead. So I have read a bit about that and even tried a short script that is exactly what I saw in the migrating to People document but when I run it (as exactly cut/pasted from the example) it fails!
const people = People.People.Connections.list('people/me', {
personFields: 'names,emailAddresses'
});
const contact = people['connections'].find((connection) => {
return connection['emailAddresses'].some((emailAddress) => emailAddress['value'] === email);
});
// Prints the contact.
console.log('Contact: %s', JSON.stringify(contact, null, 2));
I get the error:
TypeError: Cannot read properties of undefined (reading 'some')
So I know I am doing something quite wrong in the 1st place.
Also, this seems to get a contact by email address and I want to get it by name. So I know I need to change it somehow. But this seemed a good starting point.
Right now I am stumped but able to use the deprecated ContactsApp with success. However, for how long...?
Thanks