srobinson
srobinson

Reputation: 356

Gmail API: users.history.list returns "Not Found" when using pageToken

For one of our users (and only one) we frequently get a "404 Not Found" error when calling gmail.users.history.list. Specifically, it happens when we're paging through the responses (i.e. a pageToken is given) from gmail.users.history.list.

The list method is called when a Gmail push notification indicates the user has a new hisotryId, at which point we use their previous history ID to get all changes up until this point. The first call to list always succeeds, but then when using the given pageToken provided from that initial response, the call fails.

What's weird is when we see these failures in the logs and then try the same call on our own manually later on, they work just fine.

Any ideas? Thanks in advance!

Upvotes: 5

Views: 1582

Answers (2)

adu
adu

Reputation: 987

I noticed that this can also happen if your startHistoryId is too old and has expired out of Gmail's internal notifications queue.


This happened in development for me when I needed to test this feature after a long time, but had not updated any of the local history-IDs. In contrast, all of our production and staging environments were behaving well.

Upvotes: 0

Teyam
Teyam

Reputation: 8112

If you're using the same history ID from your initial call, it could be that you're using an invalid history ID. As mentioned in Users.history: list,

A historyId is typically valid for at least a week, but in some rare circumstances may be valid for only a few hours.

Try doing a full synchronization as suggested,

If you receive an HTTP 404 error response, your application should perform a full sync.

You may want to see this related SO post for additional insights.

Upvotes: 3

Related Questions