Reputation: 13735
I am trying to access Gmail messages via google API.
https://developers.google.com/gmail/api/v1/reference/users/threads
But the payload field returns the base64 of the body of the email. When an email is in a thread, it is usually to reply to a previous email. Therefore only the reply part is useful to show. The reply part can be shown by the GUI interface. Is there a way to get only the reply part via the API?
Upvotes: 1
Views: 304
Reputation: 6072
Unfortunately, there's no direct method of obtaining the last reply for each thread.
If you want to retrieve the last reply of the email threads you should first of all retrieve all the messages by using a GET
request like this:
GET https://www.googleapis.com/gmail/v1/users/userId/messages
The request response will look something like this:
{
"messages": [
users.messages Resource
],
"nextPageToken": string,
"resultSizeEstimate": unsigned integer
}
Where the users.messages
Resource looks something like this:
{
"id": "",
"threadId": ""
}
Having the list
of all the users.messages
Resources, the ones which contain the same threadId
are the emails which in fact contain replies.
So in order to obtain the last reply, you could find which threadId
s appear more than once, and then retrieve the last occurrence of it as it is the last reply. Or if you want all the replies (apart from the original email), you can retrieve all the occurrences apart from the first one (which is represented by the original email).
Lastly, to retrieve the message you can use a GET
request like this:
GET https://www.googleapis.com/gmail/v1/users/userId/messages/id
Note: The userId
is represented by the email address from which you want to retrieve the emails/replies and the id
is represented by the id
of the message.
Reference
Upvotes: 0