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:
- 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.
- 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.
msg.Idor just to a specific one? - AL.