Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gmail-api

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!

like image 863
srobinson Avatar asked Oct 30 '22 06:10

srobinson


1 Answers

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.

like image 175
Teyam Avatar answered Dec 06 '22 08:12

Teyam