2
votes

I'm fetching a message to get the full message through gmail API:

   Message msgfull = _gmailService.Users.Messages.Get("me", msg.Id).Execute(); 

I'm passing a valid msg.Id

Google.GoogleApiException: 'Google.Apis.Requests.RequestError

Not Found [404]

Google.Apis.Requests.RequestError Not Found [404] Errors [ Message[Not Found] Location[ - ] Reason[notFound] Domain[global] ]

There is also this question here

Did someone encountered this?

1
Does this occur for any valid msg.Id or just to a specific one? - AL.
only for specific ones - Tal Avissar
Are you seeing a pattern to which files it occurs (e.g. are these files actual files uploaded to the Drive or just Google Docs/Sheets)? - AL.
If you search in Gmail web for: msgid:0x<MessageIdFromGmailApi> do you see anything? - Eric D
@TalAvissar I am seeing this too - using a messageID returned from the API - user5570038

1 Answers

0
votes

This is "by design" and according to the documentation History IDs increase chronologically but are not contiguous with random gaps in between valid IDs.

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

see more here

So, If you are performing the following steps:

  1. fetching in the first step the historyIds through the history API (along with their messages ids) in these messages originated before 7 days then the history results may contain out of sync including the attached message ids and the history ids.
  2. And then trying to use the message ids from the history fetch.

A possible solution is to fetch message ids of messages only by calling users.messages.list("me") and not by relying on history queries.

Anyhow, this looks like a bug on Google API side that causes users to not able to rely on history results older that are older than 1 week in the past.

More info: Returns history records after the specified startHistoryId. The supplied startHistoryId should be obtained from the historyId of a message, thread, or previous list response. History IDs increase chronologically but are not contiguous with random gaps in between valid IDs. Supplying an invalid or out of date startHistoryId typically returns an HTTP 404 error code. A historyId is typically valid for at least a week, but in some rare circumstances may be valid for only a few hours. If you receive an HTTP 404 error response, your application should perform a full sync. If you receive no nextPageToken in the response, there are no updates to retrieve and you can store the returned historyId for a future request.