I need to connect my Gmail account with a Gmail API and to retrieve the list of email messages from my mailbox, but along with this list to have the timestamps when each message was received.

I'm using the end-point for getting "list of messages", as described here: https://developers.google.com/gmail/api/v1/reference/users/messages/list

so the response which I'm receiving has the format:

{
  "messages": [
    users.messages Resource
  ],
  "nextPageToken": string,
  "resultSizeEstimate": unsigned integer
}

where

messages[] - List of messages. Note that each message resource contains only an id and a threadId. Additional message details can be fetched using the messages.get method.

And this is a problem for me. If I want to get the timestamps, I will need to go over the complete list of returned messages, and for each of them to call the other end-point: https://developers.google.com/gmail/api/v1/reference/users/messages/get

and this end-point, returns the timestamp filed which I need

"internalDate": long

On my own, I did not find any tip in the API document of how to achieve what I need, so I was wondering if there is any way of doing this, by reducing the number of APIs to one or two?

Since looping all the messages and calling the separate end-point for each of them, is really not an option for my project. In the list of the messages, it would be ideally if I can somehow get the timestamp, alone with the other two existing fields.

0 Answers