This blog post is totally technical and just here to help fellow developers who might encounter the same issue.
If you are looking to hire a python developer, check out this outsourcing firm.
When working with the Gmail API to import messages, you first get a list of messages (with their associated
ids) and then use those
ids to get the email’s data, like this:
But sometimes, when you call the Gmail API with a
message id you just fetched using the list() method, you get an error saying:
Requested entity was not found.
How come Gmail can’t find a message it just told you exists?
Especially when the message actually exists! You can use the following link to see if one of your message exists using the
If the message does not exist when you search for it using the link above, then it actually does not exist (like a draft that was deleted)
id of a message actually seems to change in some cases - not that immutable. I haven’t fully investigated as this is out of scope but when a message gets a reply, it moves from being a simple message to being a thread - and in that case, sometimes the
When you get a list of messages, take the
message id and the
message.get() method from the API doesn’t work with the
message id, use the
threads.get() method (documentation here) to get the updated
message id and retry to get the message with that new
This will solve it! To summarize:
- Get message and thread
- Try to get the message using the
- If it doesn’t work, get the new
- Try to get the message again with the new
Hope that helps!