Gmail REST API get message function returns invalid historyId

It looks like there might be a serious problem with the Gmail REST API.

  • Call / userId / messages to get a list of messages
  • For each call / userId / messages / id to receive a message
  • Get the highest (or any) startHistoryId for each post object
  • Then call / userId / history / list passing startHistoryId as parameter

The result is unexpected. Gmail REST API returns 404 Not Found .. The returned historyId seems to be not registered or not valid.

When calling / userId / profile, startHistoryId is valid and can be successfully used in calling / userId / history / list.

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
     "domain" : "global",
     "message" : "Not Found",
     "reason" : "notFound"
    } ],
  "message" : "Not Found"
}

      

+3


source to share


1 answer


This is not a bug in the API and is documented at https://developers.google.com/gmail/api/v1/reference/users/history/list

Specifically, "History IDs increase in chronological order, but do not touch random gaps between valid IDs. Delivering an invalid or outdated startHistoryId will usually return an HTTP 404 error code. HistoryInd is usually valid for at least a week, but may be valid in some circumstances only for a few hours If you get an HTTP 404 error, your app should do a full sync.

So you are probably just using a historyId that is outside of the stored history (it doesn't last indefinitely, which would be very expensive). It lasts long enough to keep client requests in sync (like a week or so).



If you just need to sync from a specific point ahead, just use the historyId returned from getProfile. Initially, the message was about the last update of the message, which may be several months or years ago, longer than the history is being kept.

See also sync guide: https://developers.google.com/gmail/api/guides/sync

+5


source







All Articles