first ever question here!
Any pointers at all would be amazing as I don't really know where to start!
Thank you so much

From your question, I guessed that you might have wanted to retrieve the value of the profile ID of PersonMetadata. If my understanding is correct, how about the following sample script?
Please copy and paste the following script to the script editor of Spreadsheet and set your sheet name, and set the column letter of the column that the email addresses are put.
And, in this sample, People API is used. So, please enable People API at Advanced Google services.
function myFunction() {
const sheetName = "Sheet1"; // Please set your sheet name.
const column = "A"; // Please set the column letter that emails are put.
// Retrieve profile IDs of metadata of People API as an object.
const obj1 = People.OtherContacts.list({ readMask: "emailAddresses,metadata", pageSize: 1000, sources: ["READ_SOURCE_TYPE_PROFILE", "READ_SOURCE_TYPE_CONTACT"] }).otherContacts.flatMap(({ emailAddresses, metadata: { sources } }) => {
const temp = sources.find(({ type }) => type == "PROFILE");
const id = temp ? temp.id : "";
return emailAddresses.map(({ value }) => [value, id]);
});
const obj2 = People.People.Connections.list("people/me", { personFields: "emailAddresses,metadata", pageSize: 1000, sources: ["READ_SOURCE_TYPE_PROFILE", "READ_SOURCE_TYPE_CONTACT"] })
.connections.flatMap(({ emailAddresses, metadata: { sources } }) => {
const temp = sources.find(({ type }) => type == "PROFILE");
const id = temp ? temp.id : "";
return emailAddresses.map(({ value }) => [value, id]);
});
const obj = { ...Object.fromEntries(obj1), ...Object.fromEntries(obj2) };
// Retrieve email addresses from a column, and put the profile IDs to the right side of the column.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
const range = sheet.getRange(`${column}1:${column}${sheet.getLastRow()}`);
const values = range.getDisplayValues().map(([r]) => [r ? (obj[r] || null) : null]);
range.offset(0, 1).setValues(values);
}
In this sample script, it supposes that the email addresses are put into the column "A" of "Sheet1". And, when this script is run, the email addresses are retrieved from column "A" of "Sheet1", and an object including the email and the profile ID of PersonMetadata is created. And, the profile IDs of PersonMetadata are put to the right side of the column (In this case, it's column "B".) using the object.
If the row that the empty value is put means that the profile ID cannot be retrieved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With