4
votes

Gmail API history.list is returning messageId's that return 404 when message.get is called.

I call history.list with "INBOX" label and "history/messagesAdded" fields. I then call message.get with each of the messageId's returned. Some of them return valid messages, others return the following exception:

Google_Service_Exception
{
   "error": {
   "errors": [
   {
     "domain": "global",
     "reason": "notFound",
     "message": "Not Found"
    }
   ],
  "code": 404,
  "message": "Not Found"
 }
}

What would cause this? It seems like we just retrieved the messageId there isn't enough time for them to now be permanently deleted.

1
If you also get the fields history/messagesDeleted and history/labelsRemoved you will probably see that these messages have been removed. - Tholle
They will appear in both history/messagesAdded and history/messagesDeleted for the same call? - KSzeto
Yes. You will get the history from the historyId given up until now, so if the message has been added to the inbox and deleted since historyId, the same messageId will appear in both history/messagesAdded and history/messagesDeleted. - Tholle

1 Answers

2
votes

As explained in the comments, this can happen if the message was deleted. This can be checked in the messagesDeleted array return by gmail's history.list, just make sure you send the appropriate historyTypes (or doesn't send any at all).

{
 "history": [
  {
   "id": "69014",
   "messagesAdded": [
    {
     "message": {
      "id": "165a2cd1a5b308b9",
      "threadId": "1659e85b88e80e7b",
     }
    }
   ]
  },
  {
   "id": "69024",
   "messagesDeleted": [
    {
     "message": {
      "id": "165a2cd1a5b308b9",
      "threadId": "1659e85b88e80e7b",
     }
    }
   ]
  }
}