5tanczak
5tanczak

Reputation: 171

Message ID from Google Apps Script is different from ID from Gmail API

I am trying to build a Google Workspace Add-on card that pulls some information from a sheet and adds it to a Gmail card.

On the sheet, I have a list of emails with their Message ID pulled from the API (example: 1930e10b19e703er)

But the Message ID I am trying to match it to from Google Apps Script Add on function onGmailMessageOpen is different (example: "msg-f:1815195880117154226")

So it's unable to match ids and therefore can't pull in any info from the Sheet/CSV. I would like the Apps Script ID to be the same as the ID from the API.

I have tried various different methods. Here is the part of the latest script pulling in the ID.


function onGmailMessageOpen(eventObject) {
  // Defensive check for the event object
  if (!eventObject || !eventObject.gmail) {
    return createDefaultCard('No email context available');
  }

  // Activate temporary Gmail scopes to allow message metadata to be read.
  var accessToken = eventObject.gmail.accessToken;
  GmailApp.setCurrentMessageAccessToken(accessToken);

  // Get the ID of the message the user has open
  var messageId = eventObject.gmail.messageId;
  
  // Log the extracted message ID
  Logger.log('Retrieved Message ID: "' + messageId + '"');

  // Find implications from spreadsheet based on the messageId
  var implications = findImplications(messageId);

  // Create and return card
  return createImplicationsCard(implications);
}

In the logs it says Searching for EXACT Message ID: "msg-f:1815195880117154226" And then "ID in sheet: "1930e10b19e703er""

I have also tried "var messageId = e.gmail.messageId;" which also returns these same 'msg-f" ids.

Any help would be much appreciated.

Upvotes: 0

Views: 104

Answers (0)

Related Questions