Search code examples
javascriptgoogle-chrome-extensiongmail-api

How can I retrieve the messageID of an e-mail that is currently open Gmail? I'd like to label the email through Gmail API


I would like to label an email that is currently open using

POST https://gmail.googleapis.com/gmail/v1/users/{userId}/messages/{id}/modify

The problem is that I cannot find the {id} of the current message anywhere. When using users.messages.list I still don't know which messageID to use from that list.

Does anyone know where to find the id?


Solution

  • I found the answer here: https://stackoverflow.com/a/54583554/8112540

    This returns the message ID of a Gmail email that is currently open: document.querySelector('[data-message-id]').getAttribute('data-legacy-message-id')